Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Refactoring to Design Patterns

607 vues

Publié le

In this presentation we will see a brief introduction to design patterns, their origin and why we should learn them, Then we will spend most of the presentation to transform a real code sample by extracting some of the most common used patterns.

Publié dans : Logiciels
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Refactoring to Design Patterns

  1. 1. Design Patterns How to include them in existing code /Studio
  2. 2. Architecture • Wikipedia – The software architecture of a program or computing system is the structure or structures of the system, which comprise software components, the externally visible properties of those components, and the relationships between them.
  3. 3. Architecture defined - Decision • Software architecture encompasses the set of significant decisions about the organization of a software system – Selection of the structural elements and their interfaces by which a system is composed – Behavior as specified in collaborations among those elements – Composition of these structural and behavioral elements into larger subsystems – Architectural style that guides this organization Booch, Kruchten, Reitman, Bittner, and Shaw
  4. 4. Architecture defined - Irreversibility • Architecture establishes the irreversible context for design and implementation architecture CODE implementation design Architectural decisions are the most fundamental decisions; changing them will have significant ripple effects because they are hard to reverse
  5. 5. Architect defined - Irreversibility • Architect’s most important tasks is to remove architecture by finding ways to eliminate irreversibility in software designs Martin Fowler
  6. 6. Design challenges • Design is non-deterministic – Not a repeatable processes that are guaranteed to produce predictable results • Design techniques tend to be “heuristics” – “rules of thumb” – “things to try that sometimes work” • Design is an iterative process – Sloppy process – About trade-offs and priorities – Involves trial and error
  7. 7. Fundamentals heuristics • Crisp abstractions – Keep Your Design Modular – Aim for Strong Cohesion • Clear Separation of Concerns – Stratification • Accommodate human cognitive limitations • Balanced distribution of responsibilities – Find Behavior and Real-World Objects • Keep Coupling Loose – Hold connections among different parts to a minimum – Formalize Class Contracts – Encapsulate Implementation Details
  8. 8. Fundamentals heuristics • Choose simple solution – No extra parts (TDD enforce this) – Avoid Failure – Consider Using Brute Force • Design for Test • Identify Areas Likely to Change – Extensibility, Plugins, IOC, DI • Look for proven solution – Patterns
  9. 9. Patterns defined • A pattern is a proven solution to a common and recurring problem • A pattern codifies specific knowledge collected from experience in a domain • A pattern resolves forces in context • All well-structured systems are full of patterns •http://www.hillside.net
  10. 10. Patterns raise the level of abstraction • For a developer the standard design elements are objects – Everything is an object • For an architect the standard design elements are patterns
  11. 11. Patterns creates a vocabulary • “Everything is an object” is like an architect summing up a house by saying “Everything is a room” – Big room with high voltage outlets and a sink to cook – Small room upstairs to sleep • Room follow patterns and special names are created to describe it – Kitchen – Bedroom
  12. 12. Patterns simplifies communication • It enables packing a huge amount of information into a short sentence – Three-bedroom, two-bath house with an open-plan kitchen
  13. 13. Patterns are proven solutions • Not all combinations of design elements are practical • Bedroom and bathroom are separated – Bathrooms have specialized and expensive infrastructure requirements – Bathroom require maximum privacy while bedroom can be share • Bathtub and toilet end up in the same room – Both require the same infrastructure
  14. 14. Patterns avoid silly mistake • Putting a toilet next to a refrigerator • Putting dishwasher next to a bathtubs
  15. 15. Patterns and software design • Starting in the 1990s software patterns were applied in many ways with success – Design Patterrns (Gang of four 1994) – Enterprise architecture (Fowler 2002)
  16. 16. Layered Architecture • Common technique to break apart complicated software system into partition in which each partition is at a particular level of abstraction • A layer is a cohesive and tightly coupled partition that depends only on the layers below • The most simple but also the most important enterprise application patterns • The hardest part of a layered architecture is deciding what layers to have and what the responsibilities of each layer should be Presentation Infrastructure Layers Domain Logic
  17. 17. Patterns • Use Factories to delegate the production of objects. • Use Decorators to avoid hierarchy explosion. • Use Proxies to control access to objects. • Use Strategies to pass algorithms to objects. • Use Commands to pass requests to objects. • Use Template Method to delegate parts of an algorithm • Use the Composite Pattern to treat objects and collections uniformly.
  18. 18. Use Factories to delegate the production of objects.
  19. 19. Use Decorators to avoid hierarchy explosion
  20. 20. Use Proxies to control access to objects
  21. 21. Use Strategies to pass algorithms to objects
  22. 22. Use Commands to pass requests to objects
  23. 23. Use Template Method to delegate part of an algorithm
  24. 24. Use the Composite Pattern to treat objects and collections uniformly
  25. 25. Complexity 0 1 0 1 2 3 4 5 6 Local Complexity Abstraction level
  26. 26. Complexity 0 1 0 1 2 3 4 5 6 Local Global Complexity Abstraction level Confort zone
  27. 27. • Transform code to use patterns DEMO
  28. 28. The end • Remember – Pattern for common naming – Pattern to solve well known problem – Watch out for complexity • Eric De Carufel – eric@decarufel.net – http://blog.decarufel.net – http://pyxis-tech.com • Questions? 28