open-closed-principle

OO Design, open/closed principle question

I've been thinking about this object oriented design question for a while now and have unable to come up with a satisfactory solution, so thought I'd throw it open to the crowds here for some opinions. I have a Game class that represents a turn based board game, we can assume it's similar to Monopoly for the purposes of this question. I...

Design Pattern - Abstract Factory pattern and Open Closed Principle

I am a beginner in design patterns. I am trying to use Abstract Factory - pattern while maintaining Open-Closed Principle. Plz look at the following code: public interface IAbstractFormFactory { void ShowOSName(); } public class VistaForm : IAbstractFormFactory { public void ShowOSName() { ...

If I have a full unit test suite for an application, must I still apply the Open/Closed Principle (OCP)?

The Wikipedia article on OCP says (emphasis mine): ... the open/closed principle states "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"... This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and ...

Configuring Automapper in Bootstrapper violates Open-Closed Principle?

I am configuring Automapper in the Bootstrapper and I call the Bootstrap() in the Application_Start(), and I've been told that this is wrong because I have to modify my Bootstrapper class each time I have to add a new mapping, so I am violating the Open-Closed Principle. How do you think, do I really violate this principle? public sta...

Does the Factory Method pattern violate the Open/Closed principle?

Does the Factory Method pattern (not to be confused with the Factory or Abstract Factory patterns) violate the Open/Closed principle? Update: To clarify, I'm referring to the scenario where a concrete class has static factory methods on it. For example (this is from the Wikipedia page on FMP): class Complex { public static Complex...

Using IoC and Dependency Injection, how do I wrap an existing implementation with a new layer of implementation without changing existing code so as not to violate the Open-Closed principle?

I'm trying to figure out how this would be done in practice, so as not to violate the Open Closed principle. Say I have a class called HttpFileDownloader that has one function that takes a url and downloads a file returning the html as a string. This class implements an IFileDownloader interface which just has the one function. So all...

What's the most appropriate way to apply the Open-Closed Principle in this app using C#?

Scenario Each night we perform a series of calculations on about a million customer contracts. Each contract is related to one fo a group of about ten products, each of which may employ variations on the set of calculation for be performed (although the overall flow is largely the same). All the contracts for a given product will use th...

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...

Abstract methods and the Open-Closed principle

Suppose I have the following contrived code: abstract class Root { public abstract void PrintHierarchy(); } class Level1 : Root { override public void PrintHierarchy() { Console.WriteLine("Level1 is a child of Root"); } } class Level2 : Level1 { override public void PrintHierarchy() { Console.WriteLine("Level2 is a...