OO design principles & heuristics
-
Upload
dhaval-shah -
Category
Software
-
view
862 -
download
0
Transcript of OO design principles & heuristics
1
OO Design Principles and Heuristics
Dhaval Dhaval ShahShah
2
AgendaAgenda What is OO Modeling?
Why OO Modeling?
Odors of rotting software
Basic OO Principles
OO Design Principles and Heuristics
Conclusion
Case Study
3
This session will not:This session will not: Make you an expert in OOAD
Turn you into a system architect
Provide instruction on UML
4
Warning!Warning! Most of these slides maps directly/indirectly to various articles available on the web, especially from objectmentor.com
Thanks Bob!
5
What is OO ModelingWhat is OO Modeling
6
Why OO ModelingWhy OO Modeling
To Manage Change
To Deliver Faster
To Deal with Complexity
7
Odors of rotting softwareOdors of rotting software
Rigidity
FragilityImmobility
Viscosity Needless Complexity
Needless Repetition
Opacity
8
OO Design Principles and Heuristics Single Responsibility Principle
Open Close Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
9
Single Responsibility PrincipleSingle Responsibility Principle
A class should have only one reason to change
10
Single Responsibility Principle [Contd.]
11
Single Responsibility Principle [Contd.]
12
Single Responsibility Principle Single Responsibility Principle [Contd.][Contd.] What is RESPONSIBILITY?
RESPONSIBILITY is reason for change
How to spot multiple RESPONSIBILITIES?
13
Single Responsibility Principle Single Responsibility Principle [Contd.][Contd.] Example-
14
Single Responsibility Principle Single Responsibility Principle [Contd.][Contd.] Going from multiple responsibilities to single responsibility -
15
Open Close PrincipleOpen Close PrincipleSoftware entities should be open for extension but closed for modification.
16
Open Close Principle [Contd.]Open Close Principle [Contd.] Example
17
Open Close Principle [Contd.]Open Close Principle [Contd.] Example
18
Liskov Substitution PrincipleLiskov Substitution PrincipleSubtypes must be substitutable for their base types.
LSP is all about inheritance – One must be able to substitute subclass by base class without things going terribly wrong
19
Liskov Substitution Principle Liskov Substitution Principle [Contd.][Contd.] Example
20
Liskov Substitution Principle Liskov Substitution Principle [Contd.][Contd.] Example
Board board = new 3DBoard();
Unit unit = board.getUnits(8,4);
21
Liskov Substitution Principle Liskov Substitution Principle [Contd.][Contd.] Solving 3DBoard problem
22
Interface Segregation PrincipleInterface Segregation Principle
Clients should not be forced to depend upon interfaces that they don't use.
23
Interface Segregation Principle Interface Segregation Principle [Contd.][Contd.] Example
24
Interface Segregation Principle Interface Segregation Principle [Contd.][Contd.] Separation Through Delegation
25
Interface Segregation Principle Interface Segregation Principle [Contd.][Contd.] Separation Through Multiple Inheritance
26
Dependency Inversion PrincipleDependency Inversion Principle
a.High-level modules should not depend on low-level modules. Both should depend on abstractions
b.Abstractions should not depend upon details. Details should depend upon abstractions
27
Interface Segregation Principle Interface Segregation Principle [Contd.][Contd.] Layering
Naive Layering Scheme
28
Interface Segregation Principle Interface Segregation Principle [Contd.][Contd.] Inverted Layering
Inverted Layers
29
ConclusionConclusion Good design is needed to successfully deal with change
The main forces driving your design should be high cohesion and low coupling
SOLID principles put you on the right path
WARNING : these principles cannot be applied blindly :)