Presentation is loading. Please wait.

Presentation is loading. Please wait.

18 April 2005CSci 210 Spring 20051 Design Patterns 1 CSci 210.

Similar presentations


Presentation on theme: "18 April 2005CSci 210 Spring 20051 Design Patterns 1 CSci 210."— Presentation transcript:

1 18 April 2005CSci 210 Spring 20051 Design Patterns 1 CSci 210

2 18 April 2005CSci 210 Spring 20052 Design Pattern Definition The core of a solution to a problem in context –Solution can be applied in different situations –Has to be adapted to fit the needs of the specific situation –Each pattern describes a problem which occurs over and over again in our environment and then describes the core solution to that problem in such a way as to be able to use the solution many times over Not a primitive building block Not a complex domain specific design

3 18 April 2005CSci 210 Spring 20053 Design Pattern Categorization Creational Structural Behavioral

4 18 April 2005CSci 210 Spring 20054 Creational Patterns Abstract Factory Builder Factory Method Prototype Singleton – used when it is appropriate to have exactly one instance of a class

5 18 April 2005CSci 210 Spring 20055 Structural Patterns Adapter (Wrapper) Bridge Composite Decorator Façade Flyweight Proxy

6 18 April 2005CSci 210 Spring 20056 Behavioral Patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Observer State Template method Visitor

7 18 April 2005CSci 210 Spring 20057 Singleton Pattern Used when it is appropriate to have exactly one instance of a class –Window managers –Print spoolers –File systems Instances of these patterns (objects) are accessed by disparate objects throughout the software system

8 18 April 2005CSci 210 Spring 20058 Singleton Pattern (continued) Singleton allows the developer to: –Ensure that there is only one instance of the class –Provide a global point of access to the object –Allow multiple instances in the future without affecting a singleton class’s clients –Some issues remain for the definition of Singletons Web Reference –Class diagramClass diagram

9 18 April 2005CSci 210 Spring 20059 Adapter Pattern Used to enable objects with different interfaces to communicate with each other – Necessary because dissimilar elements need to interoperate –You might have a tree of objects (nodes) you want to display using Swing’s JTree. The JTree can not display your nodes directly but it can display TreeNode instances. With an adapter, you can map your nodes.

10 18 April 2005CSci 210 Spring 200510 Adapter Pattern Two flavors, object adapters and class adapters –Object adaptersObject adapters Uses a compositional technique – the adapter inherits the target interface that the client expects to see It holds an instance of the adaptee When the client calls the request() method on its target object (the adapter) the request is translated into the corresponding specific request on the adaptee

11 18 April 2005CSci 210 Spring 200511 Adapter Pattern Used to enable objects with different interfaces to communicate with each other –Class adaptersClass adapters Use multiple inheritance to achieve their goals Class adapter inherits interface of the client It also inherits the interface of the clients target Potential name conflict problem

12 18 April 2005CSci 210 Spring 200512 Composite Pattern Allows a client object to treat both single components and collections of components identically. –Composite objects contain other objects – a drawing is composed of graphics primitives (lines, circles, rectangles, text, etc) –These primitives must be drawn, moved and resized. We also want to perform the same operations on composites as well as primitive objects without distinguishing between the two.

13 18 April 2005CSci 210 Spring 200513 Composite Pattern Composite classes extend a base class that represents primitive objects. LinkLink The Composite class maintains a collection of components Composite methods can typically then be implemented by iterating over the collection of components and invoking the appropriate method for each.

14 18 April 2005CSci 210 Spring 200514 Decorator Pattern Used for adding functionality to a particular object as opposed to a class of objects (also known as a wrapper) Has an interface identical to the object it contains Any calls that the decorator gets, it relays to the object that it contains, and adds its own functionality along the way LINKLINK

15 18 April 2005CSci 210 Spring 200515 Decorator Pattern Since we are altering the behavior of an object, the decorator pattern is used at run time and can be used dynamically or removed from an object without the client realizing that anything changed. Run-time operation is more flexible than inheritance

16 18 April 2005CSci 210 Spring 200516 Observer-Observable Observers – receive communications from Observable but do not have a reference back to Observable Observable – the object that the Observers are watching. Observable maintains some type of list of references to Observers. Observable can make a call to each Observers update method. LINK

17 18 April 2005CSci 210 Spring 200517 Visitor Pattern Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.


Download ppt "18 April 2005CSci 210 Spring 20051 Design Patterns 1 CSci 210."

Similar presentations


Ads by Google