Skip to main content

Questions tagged [liskov-substitution]

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

7 votes
3 answers
546 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
5 votes
7 answers
585 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
2 votes
4 answers
315 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
3 votes
2 answers
415 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
2 votes
2 answers
452 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
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
0 votes
3 answers
314 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
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