Skip to main content

Questions tagged [liskov-substitution]

For questions about Liskov substitution principle in object-oriented design.

7 votes
3 answers
551 views

The Java List<E> interface includes methods, such as add(E) and remove(Object), that work as the names suggest on instances of mutable concrete implementations, such as ArrayList<E> and ...
Ellen Spertus's user avatar
2 votes
1 answer
200 views

I have an interface defined as follows: interface MyInterface { public function setMyMethod(int $a); public function getMyMethod(): int; } And I have a class that widens the parameter type: ...
Joao M's user avatar
  • 131
5 votes
7 answers
587 views

Consider the following scenario. I have an interface IService: public interface IService { void DoSomething(); } with an implementation: public class Implementation : IService { // This might ...
Codisattva's user avatar
1 vote
3 answers
269 views

According to Invariant rule in Liskov Substitution Principle, I know one of the form of violation of "Liskov Substitution Principle" is violating "invariants can't be weakened in a ...
wcminipgasker2023's user avatar
2 votes
4 answers
316 views

For example, I have a Label class where the default font color is black: public class MyLabel{ protected int r=0; protected int g=0; protected int b=0; public void setRGB(int r,int g,...
wcminipgasker2023's user avatar
1 vote
1 answer
150 views

Say we have the interface interface IColoredSquare { int GetSideLength(); void SetSideLength(int length); string GetColor(); } and I implement it like this class ColoredSquare : ...
user avatar
3 votes
2 answers
418 views

From Liskov Substitution Principle, I am still not very clear about the invariant rule. I read through many posts but I still have doubts. My example is picked from this blog, the example is slightly ...
riki's user avatar
  • 149
0 votes
2 answers
233 views

Recently I read about ISP and wanted to implement it into my project. While implementing my design I think I found a flaw which violates LSP but I'm not sure. Given I have a game project, in which ...
Boudebouz1's user avatar
2 votes
2 answers
456 views

According to Is this a violation of the Liskov Substitution Principle?, as I understand, the top answer currently says the code below is violating "Liskov Substitution Principle": public ...
wcminipgasker2023's user avatar
-1 votes
2 answers
268 views

I thought I understood Liskov Substitution Principle but then I thought of a case and I wanted to ask the community here if I get it right. So I read somewhere to check if we have violated Liskov or ...
Shahbaz Khan's user avatar
21 votes
6 answers
7k views

In Python 3, I subclassed int to forbid the creation of negative integers: class PositiveInteger(int): def __new__(cls, value): if value <= 0: raise ValueError("value ...
swoutch's user avatar
  • 321
2 votes
3 answers
682 views

I have a doubt about what would be the right OOP approach for implementing classes that do similar stuff with different parameters. To provide a simple example, I would use two polynomial classes, ...
ThePunisher's user avatar
0 votes
3 answers
317 views

I was reading about LSP (Liskov Substitution Principle) in a book called Clean Architecture: A Craftsman's Guide to Software Structure and Design. I have a question regarding how this would be ...
Gooday2die's user avatar
3 votes
3 answers
487 views

I have read in an article DIP in the Wild that "When Robert Martin first discussed the DIP, he equated it a first-class combination of the Open Closed Principle and the Liskov Substitution ...
bridgemnc's user avatar
  • 261
6 votes
1 answer
4k views

I'm aware that there are 4 ways to violate Liskov Substitution from here. But I'm not sure what these violations would like in practice. Can you show examples of code that breaks the principle for ...
Alexis Winters's user avatar

15 30 50 per page
1
2 3 4 5
7