120 likes | 331 Views
Ş abloane de Proiectare. Daniel POP, Ph.D. The Plan. Introducing fundamental patterns (toda y) 18 design patterns will be covered based on the case study presented in the text book (next 8 classes): Design Patterns: Elements of Reusable Object-Oriented Software
E N D
Şabloane de Proiectare Daniel POP, Ph.D
The Plan • Introducing fundamental patterns (today) • 18 design patterns will be covered based on the case study presented in the text book (next 8 classes): • Design Patterns: Elements of Reusable Object-Oriented Software • Remaining patterns (5) will be presented individually (2 classes) • Last 3 classes will be devoted to another case study: Designing a Payroll System
Definition • A pattern describes a problem which occurs over and over again in our environment, and then describes the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing it the same way twice. [Christopher Alexander, Sara Ishikawa, Murray Silverstein, Max Jacobson, Ingrid Fiksdahl-King, and Shlomo Angel. A Pattern Language. Oxford University Press, New York, 1977] • 4 essential elements: • Pattern name • Problem • Solution • Consequences • Implementation
Types of Patterns • Architectural Patterns: MVC, Layers etc. • Design Patterns: Singleton, Observer etc • We’ll do these ones • GUI Design Patterns: Window per task, Disabled irrelevant things, Explorable interface etc • Database Patterns: decoupling patterns, resource patterns, cache patterns etc. • Concurrency Patterns: Double buffering, Lock object, Producer-consumer, Asynchronous processing etc. • Enterprise (J2EE) Patterns: Data Access Object, Transfer Objects etc. • GRASP (General Responsibility Assignment Patterns): Low coupling/high cohesion, Controller, Law of Demeter (don’t talk to strangers), Expert, Creator etc. • Anti-patterns = bad solutions largely observed: God class, Singletonitis, Basebean etc.
Types of Design Patterns • Based on the type of the problem it addresses (Purpose) • Fundamental • Creational • Structural • Behavioral • Bases on the technique it uses (Scope) • Class: uses inheritance • Object: uses object composition • Remark: we’ll cover patterns from the text book, but many other design patterns exist as well; also classification may differ from one author to another.
Fundamental PatternsDelegation • Delegation = Handing of a task over another object • Consequences: • Behavior can be changed at run-time (comparing to inheritance that is static) • The ‘delegate’ is hidden to delegator’s clients • More difficult to implement comparing to inheritance
Fundamental PatternsInterface • Interface – decouples the service provider from its client • Consequences: • Programming to abstraction • Easily change the service provider • Transparency for client
Fundamental PatternsAbstract Superclass • Abstract superclass – ensures consistent behavior for its subclasses • Consequences: • Common behavior is consistent over subclasses • Variant behavior is abstract in superclass • Clients are using the abstract superclass
Fundamental PatternsInterface and Abstract Superclass • Combines Interface and Abstract Superclass patterns • Consequences: • Combines the advantages of both patterns • May provide a default behavior for the entire, or just a subset, of the ServiceIF via AbstractService
Fundamental PatternsImmutable Object • Immutable object – the internal state of the object doesn’t change after its creation • Consequences: • Only constructors can change object’s state • All member functions are const functions (in C++) • Any member function that need to change the state will create a new instance • Increase design’s robustness and maintainability • Example: • String class in JDK
Fundamental PatternsMarker Interface • A class implements a marker interface in order to support a semantic attribute of the system • Consequences: • Used by utility classes that need a specific behavior from their elements, without requesting a common base class • Example: • Cloneable, Serializable in JDK
Bibliography http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1324985583&sr=8-1 http://www.oodesign.com http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_2?ie=UTF8&qid=1324985583&sr=8-2