SOLID
Solid describes 5 principles of object-oriented programming. These can be used
individually, but together they lead to the creation of robust and maintainable
code.
Depending on the project, it may be useful to adhere to the principles with
different degrees of strictness.
Single Responsibility Principle (SRP)
The goal of the single responsibility principle is the separation of concerns within a program. This separation is achieved by ensuring a single class contains all things which have a specific reason to change and nothing more. This way each class is only responsible for the requirements of a specific thing.
Open/Closed Principle (OCP)
The entities which make up software must be open for extension (open), but closed from modifications, it needs to be extensible without changing the original (closed).
Liskov Substitution Principle (LSP)
The execution of an operation of class T on class S must lead to the same
result as executing the operation on class T if class S is a subclass of
class T. If this is not the case, the Liskov substitution principle is violated.
This leads to the requirement that subclasses must fulfill an is-a criterion.
Given the classes Circle and Ellipse, it is planimetrically correct to
assume that a Circle is an Ellipse and therefore a subclass of Ellipse.
But if Ellipse has functionalities that allow it’s axis to be scaled independently,
then a Circle is no longer an Ellipse because a Circle must always be scaled
equally in both axis.
Interface Segregation Principle (ISP)
Interfaces should be created in a way that they fit the clients needs. A client should not be forced to use interfaces it doesn’t need and the interface shouldn’t provide methods which aren’t used.
Dependency Inversion Principle (DIP)
Moduls of higher levels should not depend on modules of lower levels but on abstracts. These abstracts should not depend on details, but the details should depend on them.
Resources:
Wikipedia - SOLID
Wikipedia - Prinzipien objektorientiertes Designs
Wikipedia - Single Responsibility Principle
Wikipedia - Open-closed principle
Wikipedia - Liskovsches Substitutionsprinzip
Wikipedia - Interface segregation principle
Wikipedia - Dependency inversion principle
Last updated 27 Nov 2024, 15:01 +0100 .
What did you like?
What went wrong?