![]() ![]() So what is happening here? We have subclassed the Vehicle class and overriden the setThrottle method. Let’s use a vehicle class as an example, this vehicle has a throttle which can be set at any value between 0 and 100. The Parent Classįirst of all, let’s define our parent class or base class that contains some functionality. Let’s take a look at what these different rules mean for subclasses. Apply at the least the same rules to all output parameters as applied by the parent class.Don’t implement stricter validation rules on input parameters than those implemented by the parent class.New exceptions cannot be thrown by the methods in the sub type, except if they are sub types of exceptions thrown by the methods of the super type.Covariance of method return types in the sub type.Contra variance of method parameter types in the sub type. ![]() See a summary of the main points of the principle below: What exactly does this mean? In a basic sense it for example if you have a function that accepts a type of class which is a parent of other classes, any class that subclasses the parent class should be able to be passed in without it breaking the program. So the Liskov Substitution Principle states:ĭerived classes must be substitutable for their base classes In this article we will focus on the Liskov Substitution Principle. Dependency Inversion Principle - High level modules should not depend on low level modules.Interface Segregation Principle - Many client-specific interfaces are better than one general-purpose interface.Liskov Substitution Principle - Objects in a program should be replaceable with instances of their sub types without altering the correctness of the program.Open-Closed Principle - Software should be open for extension but closed for modification.Single Responsibility Principle - A class should have only a single responsibility / have only one reason to change.Rigidity: A change requires a lot of effort because it affects several parts of the project.Immobility: A component is difficult to reuse in another project or in multiple places of the same project because it has too many coupled dependencies.Fragility: A change may break unexpected parts, it is very difficult to detect if you don’t have a good test coverage.Let’s take a look at the problems that they seek to solve: These are a set of principles / guidelines, that when followed when developing a software system, make it more likely that the system will be easier to extend and maintain over time. In this series of posts we are going to be covering the SOLID principles of software development.
0 Comments
Leave a Reply. |