Skip to main content

Questions tagged [open-closed-principle]

The OCP is often introduced as "Software entities [...] should be open for extension, but closed for modification" (see detailed tag info for references).

4 votes
3 answers
3k views

Description I want to create an instance of an object at runtime, however, the parameters used to create the object are not always the same. To help explain, I have created a simplified example (in ...
zwoolli's user avatar
  • 151
3 votes
2 answers
266 views

There's lots of questions about the open-closed principle here, but none that I found satisfied this particular problem. At $job, I'm teaching my team Rust, but I believe the nature of this question ...
amateurece's user avatar
2 votes
6 answers
422 views

Doesnt private members and methods inherently violate the open-closed principle? Given that private, protected and public modifiers are supported. I came across this many times in codebases where ...
Code Spirit's user avatar
8 votes
7 answers
1k views

After reading What is a" feature envy" code and why is it considered a code smell?" I know the following code is suffering from "feature envy": public class Garden{ ...
wcminipgasker2023's user avatar
2 votes
4 answers
2k views

I think that I've taken the Open-Closed and Single Responsibility principles too far. Previously, I had one huge static class containing every method that has C# talk to stored procedures on my SQL ...
J. Mini's user avatar
  • 1,015
6 votes
5 answers
2k views

The UML is listed below. There are different products with different preferential strategies. After adding these products into the shopping cart, the caller needs to call the checkout() method to ...
Abner's user avatar
  • 71
-1 votes
1 answer
407 views

I am a noob in design principles and design patterns, this might seem like a very silly question. Some classes in my code have the following structure (image linked): https://ibb.co/nrp1t2g As you can ...
Shuaib's user avatar
  • 99
-1 votes
1 answer
105 views

Consider this hypothetical scenario. I have a user form that has a collection of controls that are made available/unavailable based on certain criteria. One important criterion is product type. On ...
amarsha4's user avatar
  • 176

15 30 50 per page
1
2 3 4 5