![]() Note that the setters for the Width and Height properties in the Square class have been overridden and modified to ensure that the height and width are the same. Public static Rectangle GetRectangleInstance() ![]() While the first two properties set the height and the width of the rectangle, the Area property has a getter that returns the area of the rectangle.Ī Square is a type of rectangle all of whose sides are of equal size, i.e., the width and height of a Square is the same.Ĭonsider another class called ObjectFactory. There are also three properties - Height, Width, and Area. ![]() The Rectangle class contains two data members - width and height. The Square class extends the Rectangle class and assumes that the width and height are equal.Ĭonsider the following class. The Liskov Substitution Principle represents a strong behavioral subtyping and was introduced by Barbara Liskov in the year 1987.Īccording to Barbara Liskov, "What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T."Ī classic example of violation of the Liskov Substitution Principle is the Rectangle - Square problem. In other words, derived classes should be replaceable for their base types, i.e., a reference to a base class should be replaceable with a derived class without affecting the behavior. LSP (Liskov Substitution Principle) is a fundamental principle of OOP and states that derived classes should be able to extend their base classes without changing their behavior. These include: SRP (Single Responsibility), Open/Close, Liskov's Substitution, Interface Segregation, and Dependency Inversion. The term SOLID is a popular acronym used to refer to a set of five principles of software architecture.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |