Properties Rule – History ConstraintĪ precondition should be satisfied before a method can be executed. Liskov Substitution Principle states the following: in a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e. Private int postcondition: speed = 0, and this is perfectly fine.Ĭonversely, if the class invariant is not preserved by the subtype, it breaks any client code that relies on the supertype. It enables you to replace objects of a parent class with objects of a subclass without breaking the. The above is a paraphrase of the Liskov Substitution Principle (LSP). In other words, we shall have a behavior provided by a type be described by means of abstractions and let those abstractions be used where ever the type needs to be utilized. So, let's make FixedTermDepositAccount a subclass of Account: public class FixedTermDepositAccount extends Account 3.5. The Liskov Substitution Principle is the third of Robert C. CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES. The Liskov Substitution Principle, brings together the concept of building types based on Composition rather than depending on base and derived types. This implies inheritance in our object-oriented design. A fixed-term deposit account in the real world “is a” type of account. (object-oriented programming) A principle stating that any type having a subtype should be replaceable by its subtype without altering any of the desirable. ![]() ![]() To support this, let's introduce a new FixedTermDepositAccount class. Liskov substitution principle aims to ensure that the. ![]() The bank now wants to offer a high interest-earning fixed-term deposit account to its customers. The Liskov substitution principle states that a child class must be substitutable for its parent class.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |