Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Jump Start To Ooad And Design Patterns

Internal Presentation given by Nishith

  • Inicia sesión para ver los comentarios

Jump Start To Ooad And Design Patterns

  1. 1. Nishith Shukla
  2. 2. Why OOP? ?
  3. 3. Why OOP? <ul><li>Take </li></ul><ul><li>software </li></ul><ul><li>development close </li></ul><ul><li>to </li></ul><ul><li>real life </li></ul><ul><li>In real life we deal with objects, we want to deal with software the same way. </li></ul>
  4. 4. Why OOP? <ul><li>Separation of concerns </li></ul><ul><li>In real life we need not to worry about how an object is made or what it contains for using it. </li></ul>
  5. 5. Why OOP? <ul><li>Components are replaceable </li></ul><ul><li>In real life component of similar functionality and specification are replaceable. </li></ul>
  6. 6. Why OOP? <ul><li>Develop component in parts </li></ul><ul><li>In real life developer of one component need not to worry about complete system, or how his component will be used in complete system. </li></ul>
  7. 7. Why OOP? <ul><li>Think about structure and develop prototype before getting actual instance </li></ul><ul><li>In real life we think about structure, we develop prototype like drawings before actually getting instance of objects. </li></ul>
  8. 8. Why OOP? <ul><li>Use and throw </li></ul><ul><li>In real life we use component once we are done with it we discard them. </li></ul>
  9. 9. Why OOP? <ul><li>One component can be used (reused) in multiple systems </li></ul><ul><li>In real life one component could be used for multiple systems. </li></ul>
  10. 10. Why OOP? <ul><li>Component can be pluggable </li></ul><ul><li>In real life component could be used for multiple systems. </li></ul>
  11. 11. Why OOP? <ul><li>Easy to understand system </li></ul><ul><li>In real life we can understand complex system by take top-down or bottom-up approach. Which leads us to smaller object. </li></ul>
  12. 12. What is OOP? All right, what is OOP?
  13. 13. What is OOP? <ul><li>Object-oriented programming (OOP) is a </li></ul><ul><li>programming language model </li></ul><ul><li>organized around </li></ul><ul><li>&quot;objects&quot; rather than &quot;actions“ ; </li></ul><ul><li>and “data” rather than “logic” . </li></ul>
  14. 14. Pillars of OOP <ul><li>Encapsulation </li></ul><ul><li>Inheritance </li></ul><ul><li>Abstraction </li></ul><ul><li>Polymorphism </li></ul>
  15. 15. Data Encapsulation class Account { public: float withdraw(); void deposit(float amount); private: float balance; );
  16. 16. Inheritance <ul><li>A class which is a subtype of a more general class is said to be inherited from it. </li></ul><ul><li>The sub-class inherits the base class’ data members and member functions </li></ul>
  17. 17. Inheritance cont’d <ul><li>A sub-class has all data members of its base-class plus its own </li></ul><ul><li>A sub-class has all member functions of its base class (with changes) plus its own </li></ul><ul><li>Inheritance is meant to implement sub-typing </li></ul>
  18. 18. Abstraction <ul><li>Management of complexity </li></ul><ul><li>Hierarchical classification: </li></ul><ul><ul><li>is-a relationship: inheritance </li></ul></ul><ul><ul><li>has-a relationship: containment </li></ul></ul>
  19. 19. Polymorphism <ul><li>One interface </li></ul><ul><li>Multiple implementations </li></ul><ul><li>Inheritance </li></ul><ul><li>Method overloading </li></ul>
  20. 21. OOAD Design Principals <ul><li>Single responsibility principal </li></ul><ul><li>Open closed principal </li></ul><ul><li>Liskov substitution principal </li></ul><ul><li>Dependency inversion principal </li></ul><ul><li>Interface segregation principal </li></ul><ul><li>Law of Demeter </li></ul><ul><li>Single choice principal </li></ul><ul><li>Information hiding </li></ul>
  21. 22. Single responsibility principal <ul><li>Each responsibility should be a separate class, because each responsibility is an axis of change. </li></ul><ul><li>A class should have one, and only one, reason to change. </li></ul><ul><li>If a change to the business rules causes a class to change, then a change to the database schema, GUI, report format, or any other segment of the system should not force that class to change. </li></ul>
  22. 23. Open closed principal <ul><li>A class should be open for extension but closed for modification. </li></ul><ul><li>This prevents you from introducing new bugs in existing code. If you never change it, you can't break it. </li></ul>
  23. 24. Liskov substitution principal <ul><li>Instance of subtype should be able to replace instance of base class without doing any change in the application using base class. </li></ul><ul><ul><li>If not then, class hierarchy would be mess. </li></ul></ul><ul><ul><li>If not then, unit test for super class (base class) will fail for subclass. </li></ul></ul>
  24. 25. Dependency inversion principal <ul><li>Abstractions should not depend upon details. </li></ul><ul><li>Details should depend upon abstractions. </li></ul>
  25. 26. Interface segregation principal <ul><li>The dependency of one class to another one should depend on the smallest possible interface. </li></ul>
  26. 27. Law of Demeter <ul><li>Only talk to your immediate friends. </li></ul><ul><ul><li>E.g. one never calls a method on an object you got from another call nor on a global object. </li></ul></ul><ul><li>This help in avoiding communication havoc between objects. </li></ul>
  27. 28. Single choice principal <ul><li>The exhaustive list of alternatives should live in exactly one place. </li></ul><ul><ul><li>For example there is drawing application which draws circle, rectangle and square. Than selection between these three should be written in code at only one place. </li></ul></ul>
  28. 29. Information hiding <ul><li>The basic idea is that if a object doesn't really need to know something about how another object does some job, don't make it know it. So that if first object change its internal methods, another objects are not effected. </li></ul>
  29. 30. Uncovered principal <ul><li>Reuse release equivalence principal </li></ul><ul><li>Common closure principal </li></ul><ul><li>Common reuse principal </li></ul><ul><li>Acrylic dependency principal </li></ul><ul><li>Stable dependency principal </li></ul><ul><li>Stable abstraction principal </li></ul>
  30. 31. Nishith Shukla
  31. 32. Creational Patterns <ul><li>Factory </li></ul><ul><li>Abstract Factory </li></ul><ul><li>Builder </li></ul><ul><li>Prototype </li></ul><ul><li>Singleton </li></ul>
  32. 34. Factory method <ul><li>Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory method lets a class defer instantiation to subclasses. </li></ul>
  33. 35. Factory method
  34. 36. Factory method <ul><li>public IDocument CreateDocument(String type) </li></ul><ul><li>{     if (type.isEqual(&quot;html&quot;))         return new HtmlDocument();     if (type.isEqual(“word&quot;))         return new WordDocument();     if (type.isEqual(&quot;pdf&quot;))         return new PDFDocument (); } </li></ul>
  35. 37. Factory method <ul><li>It introduce separation between application and family of classes. </li></ul><ul><li>It provides a simple way of extending the family of products. </li></ul><ul><li>If objects are created directly in application, its hard to replace/change them. </li></ul><ul><li>The factory has to be used for a family of objects. If the classes doesn't extend common base class or interface they can not be used in a factory method design pattern. </li></ul>
  36. 39. Abstract Factory Pattern <ul><li>Provide an interface for creating families of related or dependent objects without specifying their concrete classes. </li></ul>Laptop factory Desktop factory Laptop MB Desktop MB Mother Board Product Keyboard Laptop KB Desktop KB
  37. 40. Abstract Factory Pattern
  38. 41. Abstract Factory Pattern <ul><li>When to use: </li></ul><ul><ul><li>The system needs to be independent from the way the products works which are created </li></ul></ul><ul><ul><li>The system is or should be configured to work with multiple families of products </li></ul></ul><ul><ul><li>A family of products is designed to work only all together </li></ul></ul><ul><ul><li>The creation of a library of products is needed, for which is relevant only the interface, not the implementation. </li></ul></ul>
  39. 43. Builder Pattern <ul><li>Separate the construction of a complex object from its representation so that the same construction process can create different representations. </li></ul>
  40. 44. Builder Pattern
  41. 45. Builder Pattern <ul><li>When to use: </li></ul><ul><ul><li>The creation algorithm of a complex object is independent from the parts that actually compose the object </li></ul></ul><ul><ul><li>The system needs to allow different representations for the objects that are being built </li></ul></ul>
  42. 46. Difference between Builder and Abstract Factory <ul><li>Builder builds one complex object through several method calls. With Abstract Factory, every method call returns its own little object. </li></ul><ul><li>Abstract Factory allows to decide which object to create runtime, where as builder is design time decided about which complex object to construct. </li></ul><ul><li>Builder can be instructed on how to create object, Abstract factory is instructed on which object to be created. </li></ul>
  43. 48. Prototype Pattern <ul><li>Specify the kind of objects to create using a prototypical instance, and create new objects by copying this prototype. </li></ul>
  44. 49. Prototype Pattern
  45. 50. Prototype Pattern <ul><li>When to use: </li></ul><ul><ul><li>If the cost of creating a new object is large and creation is resource intensive, we clone the object. </li></ul></ul><ul><ul><li>Classes to be instantiated are specified at run-time </li></ul></ul><ul><ul><li>Avoiding the creation of a factory hierarchy is needed </li></ul></ul><ul><ul><li>It is more convenient to copy an existing instance than to create a new one </li></ul></ul>
  46. 52. Singleton Pattern <ul><li>Ensure a class has only one instance and provide a global point of access to it. </li></ul>
  47. 53. Singleton Pattern <ul><li>     </li></ul><ul><li>     private Logger () </li></ul><ul><li>{ </li></ul><ul><li>……… </li></ul><ul><li>} </li></ul><ul><li>     public static Logger GetLogger() </li></ul><ul><li>{ </li></ul><ul><li>     if (instance == null)          instance = new Logger(); </li></ul><ul><li>return instance; </li></ul><ul><li>} </li></ul>
  48. 54. Singleton Pattern <ul><li>When to use: </li></ul><ul><ul><li>When only single instance is required to be created for an object. </li></ul></ul><ul><ul><li>Object’s methods does not depend on instance of object. </li></ul></ul><ul><li>Singleton pattern can also be achieved by using static class. </li></ul>
  49. 55. Structural Pattern <ul><li>Adapter </li></ul><ul><li>Bridge </li></ul><ul><li>Composite </li></ul><ul><li>Decorator </li></ul><ul><li>Facade </li></ul><ul><li>Flyweight </li></ul><ul><li>Proxy </li></ul>
  50. 56. Behavioral Pattern <ul><li>Chain of Responsibility </li></ul><ul><li>Command </li></ul><ul><li>Interpreter </li></ul><ul><li>Repeater </li></ul><ul><li>Observer </li></ul><ul><li>Visitor </li></ul><ul><li>State </li></ul>
  51. 57. Questions? ?
  52. 58. Further references Online Books