Why should I isolate my domain entities from my presentation layer?

Quite simply, the reason is one of implementation and drift. Yes, your presentation layer needs to know about your business objects to be able to represent them properly. Yes, initially it looks like there is a lot of overlap between the implementation of the two types of objects. The problem is, as time goes on, … Read more

Are there any viable alternatives to the GOF Singleton Pattern?

To understand the proper way to workaround Singletons, you need to understand what is wrong with Singletons (and global state in general): Singletons hide dependencies. Why is that important? Because If you hide the dependencies you tend to lose track of the amount of coupling. You might argue that void purchaseLaptop(String creditCardNumber, int price){ CreditCardProcessor.getInstance().debit(creditCardNumber, … Read more

What is the point of accept() method in Visitor pattern?

The visitor pattern’s visit/accept constructs are a necessary evil due to C-like languages’ (C#, Java, etc.) semantics. The goal of the visitor pattern is to use double-dispatch to route your call as you’d expect from reading the code. Normally when the visitor pattern is used, an object hierarchy is involved where all the nodes are … Read more

Dependency Injection & Singleton Design pattern

Singletons are like communism: they both sound great on paper, but explode with problems in practice. The singleton pattern places a disproportionate emphasis on the ease of accessing objects. It completely eschews context by requiring that every consumer use an AppDomain-scoped object, leaving no options for varying implementations. It embeds infrastructure knowledge in your classes … Read more

Why is Singleton considered an anti-pattern? [duplicate]

To help with answering, here is more about the anti-pattern comment: it is overused, introduces unnecessary restrictions in situations where a sole instance of a class is not actually required, and introduces global state into an application From: http://en.wikipedia.org/wiki/Singleton_pattern For more on this you can look at: https://www.michaelsafyan.com/tech/design/patterns/singleton Here is a great ending to the … Read more

CQRS: Command Return Values [closed]

Following the advice in Tackling Complexity in CQRS by Vladik Khononov suggests command handling can return information relating to its outcome. Without violating any [CQRS] principles, a command can safely return the following data: Execution result: success or failure; Error messages or validation errors, in case of a failure; The aggregate’s new version number, in … Read more

Are utility classes evil? [closed]

Utility classes aren’t exactly evil, but they can violate the principles that compose a good object-oriented design. In a good object-oriented design, most classes should represent a single thing and all of its attributes and operations. If you are operating on a thing, that method should probably be a member of that thing. However, there … Read more

What is the difference between Strategy pattern and Dependency Injection?

DI and Strategy work in the same way, but Strategy is used for more fine-grained and short-lived dependencies. When an object is configured with a “fixed” Strategy, for example when the object is constructed, the distinction between Strategy and DI blurs. But in a DI scenario it is more unusual that the dependencies of objects … Read more