ocp

The Open/Closed Principle

The Open/Closed Principle states that software entities (classes, modules, etc.) should be open for extension, but closed for modification. What does this mean, and why is it an important principle of good object-oriented design? ...

Making a class follow OCP - Factoring functions into objects

I have a class to which I'm constantly adding to. public class OrderRepository{ public void Add(IEnumerable<Order> orders){} public void Update(IEnumerable<Order> orders){} public void Remove(IEnumerable<Order> orders){} public void Expedite(IEnumerable<Order> orders){} public void GetOrderData(Order order, DateTime...

Open-closed principle and Java "final" modifier.

The open-closed principle states that "Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification". However, Joshua Bloch in his famous book "Effective Java" gives the following advice: "Design and document for inheritance, or else prohibit it", and encourages programmers to use the "...

How do you like the data access part (with SQL Server) of Agile Principles, Patterns, and Practices in C#

How do you think about data access code like this: public void AddCusotmer(Cusotmer customer) { //save customer into database ... // save payment type SavePaymentType(customer); //save other data ... } private void SavePaymentType(Customer customer) { if(customer.PaymentType is XXXPayment) { var payment ...

How such an important principle "OCP" will be the reason of massive code duplication practice?

OCP (Open/Closed Principle) is one of the SOLID principles. Which is says: ”Software Entities should be Open for Extension, but Closed for Modification.” It take me while to understand the above sentence about OCP. And when I start read more about it, I found it make sense and so useful, but in the mean time I noticed it cause duplica...

Is the Open/Closed Principle a good idea?

This question is not about what OCP is. And I am not looking for simplistic answers, either. So, here is why I ask this. OCP was first described in the late 80s. It reflects the thinking and context of that time. The concern was that changing source code to add or modify functionality, after the code had already been tested and put into...

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

Does an API based on inheritance violate OCP? Can this be solved with a provider model/dependency injection?

I'm designing an API for the first time, and trying to follow SOLID guidelines. One of the things I find myself struggling with is balancing OCP and testability with simplicity and ease of extensibility. This open-source API is geared toward scientific modeling and computation. The aim is that various groups will be able to easily impor...

Open closed prinicple, problem

Hi, I'm trying to apply OCP to a code snippet I have that in it's current state is really smelly, but I feel I'm not getting all the way to the end. Current code: public abstract class SomeObject {} public class SpecificObject1 : SomeObject {} public class SpecificObject2 : SomeObject {} // Smelly code public class Model { publ...

How do you write code that conforms to the OCP?

I have recently been trying to learn about basic design principles and the OCP has me a bit confused. It makes sense that when a change happens it is preferable to extend the system rather than modify existing and working parts. But isn't this more of a principle for how to implement changes in a system rather than how to design one? Isn...