milad abolhassani
play

Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: - PowerPoint PPT Presentation

Design Pattern Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: http://slideshare.com/miladas http://miladas.github.io/slides Attention 2 OOP 3 Class Interface Property Abstract class Method Encapsulation


  1. Design Pattern Milad Abolhassani tuxgeek.ir milad@tuxgeek.ir Slides: http://slideshare.com/miladas http://miladas.github.io/slides

  2. Attention 2

  3. OOP 3 ● Class ● Interface ● Property ● Abstract class ● Method ● Encapsulation ● Inheritance ● Public/protected/private ● Polymorphism ● Final

  4. Where did all of these come from? 4

  5. SOLID 5 SOLID

  6. SOLID 6 ● Single Responsibility ● Open/Closed ● Liskov substitution ● Interface Segregation ● Dependency Injection

  7. Single Responsibility 7

  8. Open/Closed 8 Meyer’s open/closed ● – Once class completed, never should modified Polymorphic open/closed principle ● – Interface (public methods) – The interface is open for extension but close for modification

  9. Liskov substitution 9 Program to an interface rather than of it’s implementation ● Design by contract ● Do not extend the interface ●

  10. Interface Segregation 10

  11. Dependency injection 11

  12. What is design pattern? 12 ● In software engineering, a design pattern is a general reusable solution to a commonly occurring problem.

  13. History 13 ● Patterns originated as an architectural concept by Christopher Alexander (1977/79). ● Design patterns gained popularity in computer science after the book Design Patterns: Elements of Reusable Object-Oriented Software was published in 1994. – Gang of Four – Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John

  14. Gang of four 14

  15. Why design pattern? 15 ● Clarity ● Correctness ● Same vocabularies – Avoid miss communications ● Reuse ● Save time, trial and error ● Can speed up the development process – by providing tested, proven development paradigms ● We are not reusing code, we are reusing experience

  16. Category 16 ● Creational design patterns ● Structural design patterns ● Behavioral design patterns

  17. Creational design patterns 17 ● These design patterns provide a way to create objects while hiding the creation logic.

  18. Creational design patterns 18 ● Factory method ● Singleton ● Prototype ● Builder

  19. Factory Method 19 ● Factory Method lets a class defer instantiation to subclasses.

  20. Singleton 20 ● This pattern involves a single class which is responsible to create an object while making sure that only single object gets created.

  21. Prototype 21 ● Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

  22. Builder 22 ● Separate the construction of a complex object from its representation so that the same construction process can create difgerent representations.

  23. Programmer 23

  24. Structural design patterns 24 ● These design patterns are all about Class and Object composition. Concept of inheritance is used to compose interfaces and defjne ways to compose objects to obtain new functionalities.

  25. Structural design patterns 25 ● Adapter ● Decorator ● Facade ● Flyweight ● Proxy

  26. Adapter 26 ● Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

  27. Decorator 27 ● Attach additional responsibilities to an object dynamically.

  28. Decorator 28

  29. Facade 29 ● Wrap a complicated subsystem with a simpler interface.

  30. Flyweight 30 ● The Flyweight uses sharing to support large numbers of objects effjciently.

  31. Proxy 31 ● Use an extra level of indirection to support distributed, controlled, or intelligent access.

  32. Behavioral design patterns 32 ● These design patterns are all about Class's objects communication. Behavioral patterns are those patterns that are most specifjcally concerned with communication between objects.

  33. Behavioral design patterns 33 ● Chain of responsibility ● Mediator ● Observer ● State ● Strategy ● Template method

  34. Chain of responsibility 34 ● The Chain of Responsibility pattern avoids coupling the sender of a request to the receiver by giving more than one object a chance to handle the request.

  35. Mediator 35 ● The Mediator defjnes an object that controls how a set of objects interact. Loose coupling between colleague objects is achieved by having colleagues communicate with the Mediator, rather than with each other.

  36. Observer 36 ● Observer pattern is used when there is one-to-many relationship between objects such as if one object is modifjed, its depenedent objects are to be notifjed automatically.

  37. State 37 ● The State pattern allows an object to change its behavior when its internal state changes.

  38. Strategy 38 ● In Strategy pattern, a class behavior or its algorithm can be changed at run time.

  39. Template method 39 ● The Template Method defjnes a skeleton of an algorithm in an operation, and defers some steps to subclasses.

  40. Thank you

  41. References – JavaWorld – SourceMaking – TutorialsPoint – Informit – geekswitblogs – Wikipedia [1] [2]

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend