25 Mart 2021 Perşembe

SOLID PRINCIPLES-Sahin Kasap

 SOLID PRINCIPLES FROM MY PERSPECTIVE

Solid principles have a very important point on software development. These principles are produced after years of hardships. These details are about developing a good object-oriented program. The SOLID letters meanings are: Single Responsibility Principle, Open-Closed principle, Liskov’s substitituon principle, Interface segregation principle and Dependency Inversion principle. Let’s talk about these principles.

Single Responsibility Principle

This principle states that, in an object oriented project, a method or a class or a module must have only one responsibility. The classes/methods mustn’t do different jobs other than their own. 

Open Closed Principle

Classes or methods must be open for expanding but closed for modification, which means when a method is written and at some time of our project if we want to add another feature, we mustn’t change the existing methods, we must write another classes-interfaces for the new feature. This principle is generally achieved by creating interfaces. When a method uses the interface while dealing with the objects, the interface can be implemented for the new feature and our pre-written codes doesn’t change.

This principle is very useful in Unity, because interacting a script with an object is so easy.

Liskov’s Substitution Principle

Let me explain with my own words: if a class has a subclass and if this class has been used in some scripts, the subclass can be used too. This situation must not break anything on the application.

Interface Segregation Principle

Interfaces mustn’t be created in a way that the implementers of the interface mustn’t be forced to implement methods that they don’t use. 

Dependency Inversion Principle

This principle states that a high level module should not depend on low level modules. They all must depend on abstractions. This means that, when a low module creates another functionality, and this functionality must be used for a high module, this must be achieved by abstractions-which means we must create an interface or abstract class for the use of new functionality. So when the functionality changes, the high level must not be affected.