What is the meaning and reasoning behind the Open/Closed Principle?

It means that you should put new code in new classes/modules. Existing code should be modified only for bug fixing. New classes can reuse existing code via inheritance. Open/closed principle is intended to mitigate risk when introducing new functionality. Since you don’t modify existing code you can be assured that it wouldn’t be broken. It …

Read more

Single Responsibility Principle vs Anemic Domain Model anti-pattern

Rich Domain Model (RDM) and Single Responsibility Principle (SRP) are not necessarily at odds. RDM is more at odds with a very specialised subclassof SRP – the model advocating “data beans + all business logic in controller classes” (DBABLICC). If you read Martin’s SRP chapter, you’ll see his modem example is entirely in the domain …

Read more

SOLID vs. YAGNI [closed]

Design is the management and balance of trade-offs. YAGNI and SOLID aren’t conflicting: the former says when to add features, the latter says how, but they both guide the design process. My responses, below, to each of your specific quotes use principles from both YAGNI and SOLID. It is three times as difficult to build …

Read more

Liskov substitution principle – no overriding/virtual methods?

Subclasses overriding methods in the base class are totally allowed by the Liskov Substituion Principle. This might be simplifying it too much, but I remember it as “a subclass should require nothing more and promise nothing less” If a client is using a superclass ABC with a method something(int i), then the client should be …

Read more

In SOLID, what is the distinction between SRP and ISP? (Single Responsibility Principle and Interface Segregation Principle)

SRP tells us that you should only have a single responsibility in a module. ISP tells us that you should not be forced to be confronted with more than you actually need. If you want to use a print() method from interface I, you shouldn’t have to instantiate a SwimmingPool or a DriveThru class for …

Read more

Difference between Single Responsibility Principle and Separation of Concerns

Single Responsibility Principle (SRP)- give each class just one reason to change; and “Reason to change” == “responsibility”. In example: Invoice class does not have a responsibility to print itself. Separation of Concerns (since 1974). Concern == feature of system. Taking care of each of the concerns: for each one concern, other concerns are irrelevant. …

Read more

What is the dependency inversion principle and why is it important?

What Is It? The books Agile Software Development, Principles, Patterns, and Practices and Agile Principles, Patterns, and Practices in C# are the best resources for fully understanding the original goals and motivations behind the Dependency Inversion Principle. The article “The Dependency Inversion Principle” is also a good resource, but due to the fact that it …

Read more