Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Thanks Stuart. Given the IVehicle interface, you might have a Car, a Truck and a Motorcycle that each implements this interface. Car and Truck should have an OpenDoor method, whereas Motorcycle should not have an OpenDoor method. How would you handle this scenario to conform to LSP? Commented Dec 31, 2013 at 18:35
  • @random512 Maybe create a function with the same arguments and return type...and have it do nothing.Check this answer: stackoverflow.com/a/38923313/5233122 Commented Jun 9, 2017 at 23:21
  • @GeorgeGeschwend - I updated the answer a while back to include the OP's second question re OpenDoors. But rubber stamping methods is a clear indication of abuse of the design - we're trying to make something "fit into" or "conform to" an interface which just isn't applicable in this case. @anotherdave gives another good example of rubberstamping. Commented Jun 11, 2017 at 5:08
  • @StuartLC Sorry, I was a little green regarding Liskov principal. After watching a really good video of Bob Martin discussing SOLID, got the feeling that this principal if used as a "test". Like a Vehical base class that has an openDoor() function (behavior), and you try to let Motorcycle, which has no door, inherit it ... well, it violates the Liskov Substitution principal. Even though in the real world it is acceptable to think that a motorcycle is a vehicle, in Object Oriented Modeling this may not be the case. So what to do? Don't allow Motorcycle to inherit from Vehicle. Commented Jun 13, 2017 at 20:58
  • 1
    @Henrique it's all about not 'cheating' a polymorphic design. Design the interface, and use it as it was intended to be used. You can't override a virtual or abstract protected property in a subclass and change the scope to public, if that's what you meant. Commented Nov 26, 2020 at 23:00