solid-principles

How do I replace a switch statement with IOC so I can maintain SOLID principle

I wanted to avoid the switch statement. I have over 30 document types. There is also a possibility I will need to add more document types moving forward. I would rather pass IDocument and have the type specified in the implementation of IDocument. Something else I forgot to mention was ProgressNoteViewModel, LabViewModel ... all inhe...

Does having a method do more than one thing violate SRP?

For my purposes, I need to search for a specific node in an xml file and, if found, delete it. Should I pull search functionality out into its own method and delete functionality out into its own method? It seems more expensive to do it this way because I'll be searching the xml file once to see if it exists and searching it again to d...

How do you determine how coarse or fine-grained a 'responsibility' should be when using the single responsibility principle?

In the SRP, a 'responsibility' is usually described as 'a reason to change', so that each class (or object?) should have only one reason someone should have to go in there and change it. But if you take this to the extreme fine-grain you could say that an object adding two numbers together is a responsibility and a possible reason to ...

wrapping user controls in a transaction

I'm working on heavily dynamic and configurable CMS system. Therefore, many pages are composed of a dynamically loaded set of user controls. To enable loose coupling between containers (pages) and children (user controls), all user controls are responsible for their own persistence. Each User Control is wired up to its data/service lay...

Are SOLID principles really solid?

The first pattern stands for this acronym is SRP. Here is a quote. the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. That's is simple and clear till we start to code ) Suppose we have a class with well def...

Does using virtual methods violates LSP( L part of SOLID principles) or there are some exceptions?

Hi all, Does using virtual methods violates LSP( L part of SOLID principles) or there are some exceptions? Thanks in advance, Saghar Ayyaz ...

When implementing dependency injection, should exceptions be injected?

My team is muddling through implementing dependency injection in a PHP project using a homebaked DI container. Our first iteration of DI was perhaps taken to the extreme, and even exceptions are being injected into classes that depend on them. Is this a good practice or overkill? ...

Need help with .Net SOLID design

I'm trying to stick fast to Robert Martin's SOLID design principles for the first time, and I am not good at it. In essence, I need a hierarchy of "Node" objects. Some nodes are NodeHosts, some are NodeChildren and some are Both. Everybody's done this one before, but I can't figure out how to do it SOLID without over-complicating the ...

How to respect Open closed principle when you have business logic change ?

Hi All, We are doing some big changes in our system and I'd like to know the best way to implement these new business logic rules, respecting SOLID principles : Open / Closed principles says "Open for extension, but close for modification" ok, but how can I do modification ? I mean, I don't want to keep the old business logic, and in m...

Separation of Concerns when adding new types

I have a system I've been working on this week where I'm having a hard time balancing separation of concerns with easy extensibility. I'm adding new types to the system, and it feels like shotgun surgery. The basic idea is that data is collected (polled) from a remote system and then made available to a number of different kinds of cli...

How granular do I get with my class design when trying to follow the SOLID principles?

I have an interface for Client Registration called IRegistrationService. This contains one method called Register and it is implemented through the class RegistrationService. If I wanted to have methods for Delete, Update, Retrieve for example, would I create a separate interface for each action such as IDeletionService, IUpdateService...

Does this code smell?

Please educate me if I have code smell (violating SOLID principles, etc) Also how can I make use of IoC to make dependency injection better? Any help, tips, feedback is REALLY appreciated :) EDIT: Should all dependencies be injected from the constructor in the form of strings or should they be interfaces, if possible? For example, Logi...

SOLID vs. YAGNI

One of the most frequent agruments I hear for not adhering to the SOLID principles in the class design is YAGNI (allthough the arguer often doesn't call it that): "It is OK that I put both feature X and feature Y into the same class. It is so simple why bother adding a new class (i.e. complexity)." "Yes, I can put all my business log...

book about SOLID

Is there a really good book that explictly focuses on and walks me through SOLID (with code examples in Java or C#). ...