- single duty
- we can always replace parent class object by his sub class (try to not overload and override parents' methos) ---Barbara Liskov
- EX :
- then we need tow new functions:
- 1 do sum 2 add 100 to the sum
- these two functions will be done with class B
- if we write like this
- here when we use b to replace a, there will be errors
- so we should not override the func1, we should remain it to A and B will do the same thing as A for func1
- Higher level abstraction should not depend on lower level abstraction EX:
- mother read book :
- when we want mother to read a Newspaper: she cannot! she accept only the class Book!
- so we should do :
- interface
- here, mother as an higher level abstraction, her behavior read is not depended on the lower abstraction ---- what she will read.
- Interface isolation a class should implement the smallest interface needed to reduce the dependencies between them.
- One object should have least knowledges of another class
- Classes, modules, methods should be open to extend but closed to modification
EXs:
1 and 2 is good
3 and 4 is acceptable
5 does not obey the design principals need refactoring
6 obeys too much the design principles need refactoring
No comments:
Post a Comment