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.

Design Patterns Course


Published on

Introduction to design patterns course slides.

Published in: Technology
  • Be the first to comment

Design Patterns Course

  1. 1. Design Patterns Course Ahmed Soliman
  2. 2. Silence Please!
  3. 3. Session 1 Introduction What is so special about design patterns? OO Design Principles Strategy Meet the Observer Pattern.
  4. 4. OO Basics Abstraction Encapsulation Polymorphism Inheritance
  5. 5. What is so special about design patterns? At any given moment, somewhere in the world, someone struggles with the same software design problems you have. But better yet, someone has already solved your software design problems. Tried-and-true, road-tested, successfully used by developers to create functional, elegant, reusable, and flexible software.
  6. 6. Use inheritance Duck The Duck Game MallardDuck RedhedDuck Quack() Swim() Display() Someone wants fly() Use Interfaces Quackable Swimmable Flyable Let’s Design it together Code reuse? Waiting for a design pattern to save the day? No :P Design Priciple 1 Identify the aspects of your application that vary and separate them from what stays the same.
  7. 7. The one constant in software development
  8. 8. The one constant in software development CHANGE
  9. 9. Adding a spice of flexibility Design Priciple 2 Program to an interface, not an implementation
  10. 10. OO Design Principles Indentify the aspects of your application that vary and separate them from what stays the same. Program to an interface, not an implementation. Favor composition over inheritance
  11. 11. Strategy pattern Defines a family of algorithms, encapsulates each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
  12. 12. So? How do I use design patterns? If design patterns are so great, why can’t somebody build a library of them so I don’t have to? Aren’t libraries and frameworks also design patterns? Knowing OO basics is enough? What makes me a good OO designer?
  13. 13. The Observer Pattern
  14. 14. Observer Pattern The most heavily used pattern in the JDK Publisher + subscriber = Observer Pattern Defines a one-to-many relationship. State monitor. Definition: defines one-to-many dependency between objects so that when one object changes state, all of its dependencies are notified and updated automatically.
  15. 15. Session 2 Design Patterns Categories Decorating your Objects (Decorator) Factory Pattern Factory Method Pattern
  16. 16. DP Categories Creational Concern the ways and means of object instantiation Structural Deal with the mutual composition of classes or objects. Behavioral Analyze the ways in which classes or objects interact and distribute responsibilities among them.
  17. 17. Starbuzz Coffe Beverage getDescription() getCost() HouseBlend, DarkRoast, Decaf, Espresso.
  18. 18. OO Design Principles Classes should be open for for extension, but closed for modification. (Open-Closed Principle)
  19. 19. Decorator Pattern Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
  20. 20. Factory Pattern Pizza and PizzaStore
  21. 21. Factory Method Pattern Defines an interface for creating an object, but lets subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
  22. 22. Session 3 Singleton Pattern Command Pattern Adapter Pattern Facade Pattern
  23. 23. Singleton Pattern One of a kind objects. Static initializers? Private constructors? Useful? Ensures a class has only one instance, and provide a global point of access to it.
  24. 24. Command Pattern Encapsulates a request as an object, thereby letting you parameterize other objects with different requests, queue or log requests, and support undoable operations.
  25. 25. Adapter and Facade Patterns Adapter pattern: converts the interface of a class into another interface the clients expect. Adapters lets classes work together that couldn’t otherwise because of incompatible interfaces. Facade pattern: provides a unified interface to a set of interfaces in a subsystem. Facade defines a higher- level interface that makes the subsystem easier to use.
  26. 26. OO Design Principle Least Knowledge: talk only to your immediate friends. How java violates it? How facade use it?
  27. 27. Session 4 Iterator Pattern Composite Pattern State Pattern
  28. 28. Iterator Pattern Provides a way to access the elements of an aggregate object (collection) sequentially without exposing its underlying representation.
  29. 29. OO Design Principle Single Responsibility: A class should have only one reason to change. Cohesion: a term measures how closely a class or a module supports a single purpose or responsibility. High Cohesion -> if a class is designed around a set of related functions.
  30. 30. Composite Pattern Allows you to compose objects into tree structures to represent part-whole hierarchies, Composite lets clients treat individual objects and compositions of objects uniformly.
  31. 31. Session 5 State Pattern Proxy Pattern Compound Patterns Discussion
  32. 32. State pattern A little known fact: the strategy and state patterns were twins separated at birth. Allows an object to alter its behavior when its internal state changes. The object will appear to change its class.
  33. 33. Proxy Pattern Remote Proxy. Virtual proxy. Protection proxy. Definition: Provides a surrogate or placeholder for another object to control access to it.
  34. 34. Compound Patterns Patterns are often used together and combined within the same design solution. A compound pattern combines two or more patterns into a solution that solves a recurring or general problem.