Principles in Software Engineering
SOLID
Acronym for :
- Single responsibility : Classes should have a single resposibility
- Open/Close : Open for extension, closed for modifications
- Liskov Subsitution : References to base classes should be able to use child classes
- Interface Segregation : Clients should not be forced to depend on interfaces they do not use
- Depedency Inversion : High level modules should not depend on low level modules. Abstractions should not depend on details, but details should depend on Abstractions.
General Responsibilities Assignment Software Pattern(GRASP)
9 key principles :
- Information Expert : Give responsibility to the class that has the information needed to fulfill
- Creator : Who is responsible for creating objects. It focuses on the has-a relationship. It creates objects for components it "has" in itself. Example : A car has wheels, engine, seats, and should be responsible for creation of instances
- Low Coupling : Amount of information known between 2 classes should be minimal to promote re-use and dependency, so as to reduce the scope of changes required
- High Cohesion : Low Coupling results in High Cohesion. Assigning responsibilities to specific objects, to prevent increase coupling.
- Controller : Divide work between UI classes and non-UI classes, by creating controllers to redirect the work
- Polymorphism :
- Pure Fabrication : When we have operations that do not belong to any particular object, we create a "fake" class, in order to separate the logic.
- Indirection : Create intermediary between classes to reduce direct coupling.
- Protected Variations : Reduce impact of changes of some object on others, by making use of interfaces.