Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

OO design principles & heuristics

982 views

Published on

OO design principles & heuristics

Published in: Software
  • Be the first to comment

OO design principles & heuristics

  1. 1. 1 OO Design Principles and Heuristics Dhaval ShahDhaval Shah
  2. 2. 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. 3. 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. 4. 4 Warning!Warning!  Most of these slides maps directly/indirectly to various articles available on the web, especially from objectmentor.com Thanks Bob!
  5. 5. 5 What is OO ModelingWhat is OO Modeling
  6. 6. 6 Why OO ModelingWhy OO Modeling To Manage Change To Manage Change To Deliver Faster To Deliver Faster To Deal with Complexity To Deal with Complexity
  7. 7. 7 Odors of rotting softwareOdors of rotting software RigidityRigidity FragilityFragility ImmobilityImmobility ViscosityViscosity Needless Complexity Needless Complexity Needless Repetition Needless Repetition OpacityOpacity
  8. 8. 8 OO Design Principles and Heuristics  Single Responsibility Principle  Open Close Principle  Liskov Substitution Principle  Interface Segregation Principle  Dependency Inversion Principle
  9. 9. 9 Single Responsibility PrincipleSingle Responsibility Principle A class should have only one reason to change
  10. 10. 10 Single Responsibility Principle [Contd.]
  11. 11. 11 Single Responsibility Principle [Contd.]
  12. 12. 12 Single Responsibility Principle [Contd.]Single Responsibility Principle [Contd.]  What is RESPONSIBILITY?  RESPONSIBILITY is reason for change  How to spot multiple RESPONSIBILITIES?
  13. 13. 13 Single Responsibility Principle [Contd.]Single Responsibility Principle [Contd.]  Example-
  14. 14. 14 Single Responsibility Principle [Contd.]Single Responsibility Principle [Contd.]  Going from multiple responsibilities to single responsibility -
  15. 15. 15 Open Close PrincipleOpen Close Principle Software entities should be open for extension but closed for modification.
  16. 16. 16 Open Close Principle [Contd.]Open Close Principle [Contd.]  Example
  17. 17. 17 Open Close Principle [Contd.]Open Close Principle [Contd.]  Example
  18. 18. 18 Liskov Substitution PrincipleLiskov Substitution Principle Subtypes 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. 19. 19 Liskov Substitution Principle [Contd.]Liskov Substitution Principle [Contd.]  Example
  20. 20. 20 Liskov Substitution Principle [Contd.]Liskov Substitution Principle [Contd.]  Example Board board = new 3DBoard(); Unit unit = board.getUnits(8,4);
  21. 21. 21 Liskov Substitution Principle [Contd.]Liskov Substitution Principle [Contd.]  Solving 3DBoard problem
  22. 22. 22 Interface Segregation PrincipleInterface Segregation Principle Clients should not be forced to depend upon interfaces that they don't use.
  23. 23. 23 Interface Segregation Principle [Contd.]Interface Segregation Principle [Contd.]  Example
  24. 24. 24 Interface Segregation Principle [Contd.]Interface Segregation Principle [Contd.]  Separation Through Delegation
  25. 25. 25 Interface Segregation Principle [Contd.]Interface Segregation Principle [Contd.]  Separation Through Multiple Inheritance
  26. 26. 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. 27. 27 Interface Segregation Principle [Contd.]Interface Segregation Principle [Contd.]  Layering Naive Layering Scheme
  28. 28. 28 Interface Segregation Principle [Contd.]Interface Segregation Principle [Contd.]  Inverted Layering Inverted Layers
  29. 29. 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 :)

×