Click here to Skip to main content
15,881,852 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: The balance between architecture and code Pin
raddevus27-Apr-21 9:56
mvaraddevus27-Apr-21 9:56 
GeneralRe: The balance between architecture and code Pin
Marc Clifton28-Apr-21 2:51
mvaMarc Clifton28-Apr-21 2:51 
GeneralRe: The balance between architecture and code Pin
honey the codewitch27-Apr-21 11:11
mvahoney the codewitch27-Apr-21 11:11 
GeneralRe: The balance between architecture and code Pin
MSBassSinger27-Apr-21 11:32
professionalMSBassSinger27-Apr-21 11:32 
GeneralRe: The balance between architecture and code Pin
honey the codewitch27-Apr-21 12:18
mvahoney the codewitch27-Apr-21 12:18 
GeneralRe: The balance between architecture and code Pin
Mycroft Holmes27-Apr-21 12:20
professionalMycroft Holmes27-Apr-21 12:20 
GeneralRe: The balance between architecture and code Pin
rob tillaart27-Apr-21 21:42
rob tillaart27-Apr-21 21:42 
GeneralRe: The balance between architecture and code Pin
Fabio Franco27-Apr-21 22:56
professionalFabio Franco27-Apr-21 22:56 
I had been there so many times that it just screams to me all the balancing only experience taught me. Usually learning materials are not really in touch with reality and all the ways it can variate.

My experience is that:

1 - The first step is to try anticipating the scale and lifetime of a project. This will help avoid unnecessary over or under-engineering. Patterns exist to help us, but they are often not worth the cost and can create a huge technical debt in the team.

2 - Code reuse is a double edged sword. It can both help to prevent bugs, but also create bugs. When dealing with complex systems, creating a single business rules model can be very bad. You start twisting and over abstracting so much that the codebase starts becoming very hard to understand, creates a lot of coupling and unpredictable side effects. Applying DDD here is beneficial as you separate an often "Big Ball of Organized Mess" into smaller more manageable contexts (bounded contexts). That will somewhat generate code duplication, but I believe it to be a good thing as the chances of side effects are greatly reduced and allows different business domains to evolve independently. Of course, this requires some mindfulness on the impact of a change in the big pictures, but scenarios like the one below are so much easier to deal with, that's worth the code repetition (and some times data):

Consider a hypothetical system where we have an employee class which are part of two different business domains:
1 - Payroll Management: For payroll management, you need a model that contains properties like: salary, working schedule, name, address, tax number, email. It should contain methods like calculatePayrollTaxes, calculateNetSalary, calculateIncomeTaxes, updatePersonalInfo

2 - Sales: For sales rules you likely need a whole different approach for the employee rate. For example. In a commissioned scheme, you'd need the following properties: commission rate, name, mtdCost. The methods could probably be much more focused like just having calculateCommission.

Because the P&L report needs to account for the costs of the employee, a change in payroll taxes, salary or work schedule will affect the month to date costs. But that can be kept in its entirety contained within Employee entity of the Payroll Management context, without having a huge class with all rules that involve employees. It makes a lot easier to maintain its business rules, doesn't require and endless number of abstraction layers and has much lower chances of causing side effects. It does require a top level architecture that accounts for changes that may affect other domains (for example, the case of the Sales department getting the update on mtdCost). But that can be solved simply over multiple ways that don't require direct coupling of both business context objects.

Now, with a very slim object the sales context is allowed a lot of freedom to objectively evolve objectively and more business oriented, which provides more value and leads to less conflicts. But let's say that the rules for employee names change (which is a shared and repeated property). So the Peyroll Context changes it to split that property in FirstName and LastName.

The first thing you can notice from this change is that it may impact the Employee under the Sales context. But for sales, it still doesn't care that the employee has different properties for first and last names. If you design this properly, you don't even need to care to change anything outside the employee context. Because you can:

1 - Propagate the change in the exact same way. If you use webhooks, direct rest calls or messaging to do interservice communication, you can simply concatenate those properties when you change your model. Everyone else will get those changes the same way they were getting before. You fulfil your need to change the model and don't change what doesn't need change.

2 - If you use a shared database (or tables so to speak) and monolith approach between contexts, you can still apply a similar approach, although not exactly ideal, but you can have the separation of schemas through a unified ORM layer that will account for changes in a shared data model to avoid conflicts. I would personally avoid that as there are multiple ways to (even within a single database) to keep entities separate as they are not really the same entity within the different business contexts and leverage the concept of Domain Events where all other interested domains can subscribe to, which completely eliminates the coupling trap I have fallen to many times over.

But in the end, if you have a simple project, you can simply create a "Small ball of organized mess", which will ship fast, is still easy and small enough to maintain and also adds little effort for an eventual need of refactor to scale.

Getting the sweet spot right to me, is the real challenge. And that is the thing that only experience has taught me and I really fail to contemplate a more effective way to teach that.

To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson


Our heads are round so our thoughts can change direction - Francis Picabia

GeneralRe: The balance between architecture and code Pin
KateAshman27-Apr-21 23:45
KateAshman27-Apr-21 23:45 
GeneralRe: The balance between architecture and code Pin
GuyThiebaut27-Apr-21 23:50
professionalGuyThiebaut27-Apr-21 23:50 
GeneralRe: The balance between architecture and code Pin
Dan Sutton28-Apr-21 5:27
Dan Sutton28-Apr-21 5:27 
GeneralThought of the Day Pin
OriginalGriff27-Apr-21 4:53
mveOriginalGriff27-Apr-21 4:53 
GeneralRe: Thought of the Day Pin
jeron127-Apr-21 5:02
jeron127-Apr-21 5:02 
GeneralRe: Thought of the Day Pin
megaadam27-Apr-21 7:16
professionalmegaadam27-Apr-21 7:16 
GeneralRe: Thought of the Day Pin
W Balboos, GHB27-Apr-21 8:01
W Balboos, GHB27-Apr-21 8:01 
GeneralRe: Thought of the Day Pin
Daniel Pfeffer27-Apr-21 9:44
professionalDaniel Pfeffer27-Apr-21 9:44 
GeneralRe: Thought of the Day Pin
DRHuff27-Apr-21 12:42
DRHuff27-Apr-21 12:42 
QuestionCovid Question of the Moment Pin
megaadam27-Apr-21 4:10
professionalmegaadam27-Apr-21 4:10 
AnswerRe: Covid Question of the Moment Pin
W Balboos, GHB27-Apr-21 4:13
W Balboos, GHB27-Apr-21 4:13 
JokeRe: Covid Question of the Moment Pin
Daniel Pfeffer27-Apr-21 4:16
professionalDaniel Pfeffer27-Apr-21 4:16 
GeneralRe: Covid Question of the Moment Pin
W Balboos, GHB27-Apr-21 4:49
W Balboos, GHB27-Apr-21 4:49 
GeneralRe: Covid Question of the Moment Pin
Daniel Pfeffer27-Apr-21 7:39
professionalDaniel Pfeffer27-Apr-21 7:39 
GeneralRe: Covid Question of the Moment Pin
Jörgen Andersson27-Apr-21 12:02
professionalJörgen Andersson27-Apr-21 12:02 
AnswerRe: Covid Question of the Moment Pin
RickZeeland27-Apr-21 4:17
mveRickZeeland27-Apr-21 4:17 
GeneralAn overhaul of the second kind Pin
W Balboos, GHB27-Apr-21 2:32
W Balboos, GHB27-Apr-21 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.