The LSP Liskov's Substitution Principle (or LSP) is about abstraction. Imagine a class Shape and two classes Square and Rectangle deriving from Shape. Now Shape has a (virtual) method getArea(). You would expect it to return the area that is covered by the (concrete, instanced!) shape regardless of what type...
java,interface,immutability,code-smell,lsp
In my view, an ImmutableMap should implement Map. It would be a bad idea not to implement Map as there are many methods that accept a Map as an argument and only use it in a read-only sense. I don't believe this does violate the Liskov Subsitution principle because the...
No as long as all the methods inherrited from the parent class follow the same contract as the parent then LSP is preserved. the whole point of LSP is to be able to pass around a subclass as the parent class without any problems. It says nothing about not being...
In Java, methods are virtual by default. In C++, member functions are non-virtual by default. So to mimic the Java example, you need to declare the member functions virtual in the base class.
What am I getting wrong? I think most helpful would be an example of how a value can be passed that violates the assumptions the code makes about that value. You didn't misunderstand LSP, allowing a bigger type in a subclassed method doesn't violate the principle; in fact, what...
solid-principles,duck-typing,lsp
I think you get it. Refused Bequest is a code smell. But, what type of code smell? Quoting Martin Fowler's book Refactoring: improving the design of existing code: Subclasses get to inherit the methods and data of their parents. But what if they don't want or need what they are...
inheritance,class-design,downcasting,class-hierarchy,lsp
LSP is all about behavioral subtyping. Roughly speaking, B is a subtype of A if it can be always used where A is expected. Moreover, such usage shouldn't change expected behavior. So, considering LSP application, the main point is what "expected behavior of A" is. In your example, it is...
I think what you're encountering is not so much a Liskov Substitution Principle violation as you are encountering a polymorphism limitation in most languages. With something like List<CalendarBaseItem> the compiler is inferring that you're only dealing with CalendarBaseItem which obviously can't be true if CalendarBaseItem is abstract--but that's what a...
scala,immutability,lsp,mutability,uap
That's related to the Liskov Substitution Principle: you can't assign weaker access privileges in subclass (even for Java). Making var a def makes the setter def x_= (y: T ): Unit private (as @Staix said). So in case when Seadan Car has formal type Car it should not be accessed,...