open-closed-principle Questions
2
Solved
In studying for the Java certification test I learned that static initialization blocks run once when the class is loaded, in order of appearance within the source code, that instance initializatio...
Supplejack asked 16/12, 2013 at 20:9
1
Solved
For the first time in a LTS version of Java (Java 17) we have the sealed keyword that, in a nutshell, give us the possibility to restrict the hierarchy:
public abstract sealed class Person
permits...
Buffy asked 4/12, 2021 at 19:7
5
The DIP states:
High-level modules should not depend on low-level modules. Both should depend on abstractions.
Abstractions should not depend upon details. Details should depend upon abstrac...
Advisee asked 25/8, 2013 at 10:29
14
Solved
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...
Quiroz asked 12/9, 2008 at 13:48
3
Solved
It looks to me like Bob Martin needed something starting with O to make SOLID and found in some old book this (possibly useless) Open/Closed principle.
How can Open/Closed co-exists with the Singl...
Pentose asked 26/2, 2016 at 17:31
2
Java 8 introduced the concept of default implementation for interfaces? Isn't this violating Open Closed Principle, since based on the example on https://docs.oracle.com/javase/tutorial/java/IandI/...
Yerkovich asked 18/4, 2017 at 0:30
3
Solved
I know that open closed principle mean open for extension and closed for modification. Consider an example as follows
public class Vehicle{
public void service(){
//vehicle servicing code
}
}
...
Elyot asked 7/4, 2015 at 17:54
2
Solved
The factory in this tutorial obviously violates the OCP. Every time a shape is added to the system, we need to add it in the factory to support it.
I'm thinking of another implementation and I'd li...
Permeate asked 12/4, 2020 at 7:25
1
I am currently going through the design patterns of OPP. Just to give you some background. This is not my first time encountering the patterns. I've been programming for a while (decade or so...
Scribe asked 21/3, 2020 at 22:55
1
Solved
I have a following structure to use Open Close Principle
class Payment{
//this is not a model class
// according to OC principle this class should not focus on the implementation
private $pa...
Dasilva asked 7/3, 2019 at 9:50
3
Solved
From Wikipedia :
The idea was that once completed, the implementation of a class could only be modified to
correct errors; new or changed features would require that a different class be crea...
Rosetterosewall asked 20/12, 2012 at 19:29
2
Solved
I have two checked exceptions: TestException1 and TestException2 and the following code:
void p1() throws TestException1{
p2();
}
void p2() throws TestException1 {
p3();
}
void p3() throws Te...
Abercromby asked 26/2, 2019 at 9:30
4
Solved
I have been looking into the open closed principle and it sounds good and so I wanted to exercise it's teachings.
I looked at applying my new found knowledge to an existing project and have become ...
Eozoic asked 22/8, 2011 at 15:3
4
Solved
The Single Responsibility Principle states that:
A class should have one, and only one, reason to change.
The Open/Closed Principle states that:
You should be able to extend a classes behav...
Missis asked 9/3, 2018 at 15:46
7
Solved
As SOLID principles say, it's better to remove switch conditions by converting them to classes and interfaces.
I want to do it with this code:
Note: This code is not real code and I just put my...
Gobbet asked 7/3, 2018 at 8:49
4
The open/closed principle states that a class should be open for extension but closed for modification.
I thought that the modification part referred strictly to altering the source code of the ba...
Huth asked 14/6, 2016 at 11:41
2
Solved
I'm playing around with subclassing vs Interfaces and composition. I end up getting confused about a few things when it comes to the code duplication. As we all know there are alot of scenarios whe...
Nubilous asked 29/1, 2018 at 19:16
1
Solved
I understand that this principle states that a module is open for extension but closed for modification, and this is clear when we want to upgrade/modify a method in some class - we create another ...
Softcover asked 28/6, 2017 at 8:19
5
I'm new to OOP and learning design patterns so I wrote some simple code to try out a Factory Method, and all seems well, except when I want to add another sub-type. Here's the code so far:
public ...
Sign asked 20/1, 2017 at 16:26
3
Solved
In java, If we are using an enum and eventually we want to add/remove an attribute to/from that enum, hence its usages, we are violating open/closed principle in solid principles.
If so, wha...
Vanya asked 15/7, 2016 at 9:59
1
Solved
Scenario: I stored some information (e.g. an array of doubles) in a class field (say field Measurements, array of integers in a class MeasureData). Now I would like to use this data to perform some...
Outshine asked 4/5, 2016 at 18:38
1
I understand that one of the main advantages of the Factory Method over Simple Factory is that it doesn't violate the Open-Closed SOLID Principle. That is, the former doesn't require modifying the ...
Bloem asked 17/2, 2015 at 17:52
3
Solved
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 conc...
Loudmouthed asked 4/3, 2010 at 17:4
3
Solved
I just created the following method in one of my classes
public static bool Assimilate(this List<Card> first, List<Card> second)
{
// Trivial
if (first.Count == 0 || second.Count == ...
Ania asked 25/4, 2014 at 16:9
6
I want to refactor the following code to avoid if...else so that I don't have to change the method every time a new survey type comes in (Open/closed principle). Following is the piece of cod...
Perfoliate asked 27/3, 2014 at 4:51
1 Next >
© 2022 - 2024 — McMap. All rights reserved.