![]() (The base class has a method that always returns a value in the range 1 - 100 but the child class needs to return a value of 101.)Ī subclass needs to provide an exception condition that was not present in the base class (unless the exception object is itself a subclass of a valid exception object raised by the base class).Ī common example showing a violation of the LSP is the classic "Is a circle an ellipse" question. (The base class has a method that accepts any SomeBaseClass as a parameter, but the child class requires a ClassInheritedFromSomeBaseClass.)Ī subclass needs to weaken postconditions. The LSP may not be completely appropriate if:Ī subclass needs to strengthen preconditions. It is expected, or desired, that the code using on the base class will be reused elsewhere and may encounter alternate derived classes. (An example would be the Strategy pattern where the caller should not require any additional information about the specifics of the strategy.) There is no reason for the underlying processing to know about any more than the base class. Subclasses with more constraints than base classes ![]() ![]() Design By Contract simply specifies the part of the behavior which must remain unchanged in a given scenario.Įrrors could be raised by a subclass that are not expected/raised by the base class Note also that Design By Contract does not imply (or require) use of the LSP. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |