Questions tagged [open-close]

29 questions
61
votes
8 answers

LSP vs OCP / Liskov Substitution VS Open Close

I am trying to understand the SOLID principles of OOP and I've come to the conclusion that LSP and OCP have some similarities (if not to say more). the open/closed principle states "software entities (classes, modules, functions, etc.) should be…
38
votes
8 answers

Is overriding Object.finalize() really bad?

The main two arguments against overriding Object.finalize() is that: You don't get to decide when it's called. It may not get called at all. If I understand this correctly, I don't think those are good enough reasons to hate Object.finalize() so…
AxiomaticNexus
  • 776
  • 2
  • 7
  • 11
19
votes
1 answer

Why does(/did) Bertrand Meyer think subclassing is the only way to extend a "closed" module?

In Meyer's Object-Oriented Software Construction (1988) he defines the open/closed principle as follows: A module will be said to be open if it is still available for extension. For example, it should be possible to add fields to the data…
14
votes
4 answers

Do mocks violate the Open/Closed principle?

Some time ago I read, on a Stack Overflow answer that I can't find, a sentence that explained that you should test public APIs, and the author said that you should test interfaces. The author also explained that if a method implementation changed,…
Christopher Francisco
  • 2,392
  • 1
  • 12
  • 27
12
votes
7 answers

Refactoring and Open / Closed principle

I have recently being reading a web site about clean code development (I do not put a link here because it is not in English). One of the principles advertised by this site is the Open Closed Principle: each software component should be open for…
Giorgio
  • 19,486
  • 16
  • 84
  • 135
12
votes
5 answers

Is overloading an example of the Open/closed principle?

Wikipedia says "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification" The word functions caught my eyes, and I now wonder if we can assume that creating an overload for a method can be…
Saeed Neamati
  • 18,142
  • 23
  • 87
  • 125
9
votes
2 answers

Static factory method in base class

An increasingly popular definition of factory method is: a static method of a class that returns an object of that class' type. But unlike a constructor, the actual object it returns might be an instance of a subclass. From :…
q126y
  • 1,713
  • 3
  • 14
  • 24
8
votes
5 answers

Open Closed principle in design patterns

I am bit confused about how Open Closed principle can be applied in real life. Requirement in any business changes over the time. According to Open-Closed principle you should extend the class instead modifying the existing class. To me every time…
parag
  • 181
  • 2
7
votes
2 answers

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. The gamepad has buttons, switches and sticks while…
7
votes
2 answers

Does this factory method pattern example violate open-close?

In Head-First Design Patterns, they use a pizza shop example to demonstrate the factory method pattern. public abstract class PizzaStore { public Pizza orderPizza(String type) { Pizza pizza; pizza = createPizza(type); …
William
  • 195
  • 5
6
votes
5 answers

How to refactor this code to obey the ‘open-closed’ principle?

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 calculate the totalPrice and loyaltyPoints according…
Abner
  • 71
  • 7
6
votes
6 answers

In creating a "registry", which is worse: using reflection or violating open/closed principle?

In my current software engineering course, my team is working on a library management system that is essentially a command-line/REPL environment with a half dozen commands, e.g. checkout, search, etc. We've elected to use the command pattern for…
5
votes
2 answers

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 Evans and Martin Fowlers creates some abstraction and…
5
votes
1 answer

Peculiar architecture interfacing .NET to AutoCAD out-of-process

I have written a set of classes to interact with AutoCAD from an out-of-process .NET assembly, but it seems like my class architecture and interactions are unusual. I am struggling to find a better way to design these. Some background: I am reading…
Mike
  • 649
  • 4
  • 11
5
votes
2 answers

Does agile contradict to Open/Closed principle?

O/C principle dictates that production code should not be changed if system behavior augmention is required. Otherwise it becomes hard to trust tests. Following it as a dogma we are going to end with either deep inheritance trees or aggregations. On…
Pavel Voronin
  • 1,640
  • 1
  • 18
  • 25
1
2