default Flashcards
Single Responsablity (Separation of concerns)
“There should never be more than one reason for a class to change”
Applies to a class, an interface, trait and method/function
Open Closed Principle
Open for extension, closed for modification
liskov substitution principle
if we have an interface that accept a base class we should be able to stick a derived class also
” the subtype S implements its own class attribute phi of type string instead of list. This violates Liskov’s theory. You can no longer replace T with objects of type S.”
Interface Segregation Principle (ISP)
states that clients should not be forced to depend upon interface members they do not use.
ISP proposes that the interfaces be broken down into multiple, small cohesive interfaces so that no class is forced to implement any interface, and therefore methods, that it does not need.
Suggestions for Object Oriented Design
Separate out parts of code that vary or change from those that remain the same.
Always code to an interface and not against a concrete implementation.
Encapsulate behaviors as much as possible.
Favor composition over inheritance. Inheritance can result in explosion of classes and also sometimes the base class is fitted with new functionality that isn’t applicable to some of its derived classes.
Interacting components within a system should be as loosely coupled as possible.
Ideally, class design should inhibit modification and encourage extension.
Using patterns in your day to day work, allows exchanging entire implementation concepts with other developers via shared pattern vocabulary.
Creational design patterns relate to
how objects are constructed from classes. New-ing up objects may sound trivial but unthoughtfully littering code with object instance creations can lead to headaches down the road.
Creational design patterns types
Builder Pattern
Prototype Pattern
Singleton Pattern
Abstract Factory Pattern
Structural design patterns are concerned with the
composition of classes i.e. how the classes are made up or constructed
Structural patterns types
Adapter Pattern
Bridge Pattern
Composite Pattern
Decorator Pattern
Facade Pattern
Flyweight Pattern
Proxy Pattern
Behavioral design patterns dictate the
interaction of classes and objects amongst eachother and the delegation of responsibility
Behavioral design patterns