Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [open-closed-principle]

The tag has no usage guidance.

3
votes
2answers
113 views

Clarification about an example of the polymorphic open/closed principle

My question is regarding the polymorphic Open-Closed Principle. Say I have the following client: public class Client { private Server server; public Client(Server server) { this....
1
vote
2answers
226 views

Liskov Substitution Principle

I am trying to wrap my mind around a Liskov Substitution Principle and I came across this article. SOLID Class Design: The Liskov Substitution Principle In this article, the author gives an example ...
8
votes
2answers
364 views

Difficulty making this class open-closed

Here is my problem: I want to read input from different HID devices such as a gamepad, racing well, joystick, etc. Pretty much any game controller. The issue is that they all have different inputs. ...
1
vote
1answer
57 views

Ensure encapsulation and Open/Closed principle with Command pattern?

I'm developing a small multiplayer game. It'll be served by one websockets server and consumed by multiple consumers. As such I need to be cautious about concurrency errors. The general software ...
7
votes
2answers
656 views

Liskov's substitution principle : If subtype has some extra behaviour implemented, which is not present in type, then is this violation of LSP?

In my quest to write better, cleaner code, I am learning about SOLID principles. In this, LSP is proving to be little difficult to grasp properly. My doubt is what if I have some extra methods in my ...
2
votes
2answers
128 views

Is replacing the call to mutual exclusive methods by an injected strategy overengineering?

I recently gave advice to refactor some code along the lines of class Validator<T> : IValidator { public ValidationResult Validate(Validatable thingToValidate) { if(typeof(T)....
3
votes
1answer
100 views

Should files/data follow rules like 'open-closed principle'?

Does 'open-closed principle' also includes files and data of the app? According to https://softwareengineering.stackexchange.com/a/296955/248528, it says files and data are't included, but it doesn't ...
3
votes
3answers
840 views

Following Open Closed Principle

I try to write "clean code" for most of the time. But practically find it very hard, meaning - gradually business requirements changes dramatically or the business requirement which seems like just a ...
0
votes
4answers
261 views

The Open/Closed Principle, how does it work for adding entities?

I'm not even sure how to ask this, but here goes: Let's say I have a Web application that incorporates Teachers, Courses and Students in such a way that I can do things like this (pseudocode): ...
6
votes
4answers
605 views

Properly re-design from Switch to Polymorphism (Open/Close principle)

I'm having major troubles trying to get rid of this switch statement. To put a little of context first, I'm working with asynchronous batch operations. These operations can be applied to any entity in ...
-2
votes
2answers
198 views

Change in constructor parameter or ways to decompose the constructor? [duplicate]

Class Book { private int year; private String session; private int volume; private int number; private String khand; private Date proceeding_date; private int pageNo; Book(year,session,...
3
votes
3answers
257 views

If an enum is used without bitwise operation, and all of its values are predefined individually, is it violating open closed principle?

For example, if I use an enum, which all values are manually defined individually, for example: public enum MyNum{ Zero(0), One(1), Two(2); private final int value; MyNum(int ...
7
votes
1answer
450 views

How do I make this Open/Closed example also obey Single-Responsibility?

This is a simple example, but it reflects a tension between SOLID principles that I often find myself struggling with. A popular example of the Open/Closed Principle (e.g. [1], [2]) imagines that you ...
6
votes
4answers
2k views

In DDD, how do I persist an aggregate containing polymorphism

I've been developing applications according to the principles of DDD for a while now, and, as many, I often run into issues when it comes to persisting an aggregate. One of the main advantages of DDD ...
5
votes
2answers
329 views

Specification pattern and open closed principle

I'm studying the SOLID principles and I'm having some troubles dealing with the Specification Pattern and the open/closed principle. The fact is that the Specification pattern introduced by Eric ...
2
votes
1answer
571 views

Open/Closed principle, good practices, and business rules

I'm discovering craftsmanship and trying to learn it, and I decided first to understand how to work with the SOLID principles. I'm actually facing some troubles while dealing with the Open/Closed ...
2
votes
2answers
157 views

Can “do something depend on input” obey open closed principle?

For example, I have something need to do depend on user input: test.cpp #include <iostream> #include <fstream> int main(){ std::string input; std::cin >> std::noskipws >&...
5
votes
7answers
699 views

Is it appropriate to not follow the O/C principle if you have unit test coverage?

I find it more convenient to 'modify'existing classes rather than extending them. Thus, I violate the open closed principle of 'not modifying the compiled and tested source code, instead extending the ...
4
votes
3answers
474 views

Command pattern and open-closed-principle

Does the command pattern uses OCP ? In a command patter the invoker is only extensible by actually extending the class. If we want to add custom methods to it, we can make our own sub-class or we ...
1
vote
4answers
410 views

Understanding Bob Martin's Closed For Modification Explanation

“Closed for modification.” Extending the behavior of a module does not result in changes to the source or binary code of the module. The binary executable version of the module, whether in a ...