Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services.

Similar presentations


Presentation on theme: "Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services."— Presentation transcript:

1 Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services

2 Design Pattern l Introduction: why a design pattern? Introduction: why a design pattern? l History of design pattern History of design pattern l What is a design pattern What is a design pattern l How we describe design pattern How we describe design pattern l Classification of desing pattern Classification of desing pattern l Examples of design pattern Examples of design pattern l Conclusions Conclusions l Bibliography Bibliography

3 Why a Design Pattern l Reusability:one of Wasserman’s rules(1996)for an efficient and actual SE discipline l Helping new designers to have a more flexible and reusable design l Improving the documentation and maintenance of existing system by furnishing an explicit specification of class and object interactions and their intent

4 History of Design Pattern l 1979:Christopher Alexander,architect, “The Timeless Way of Building”,Oxford Press l 1987:OOPSLA (Object Oriented Programming System),Orlando, presentation of design pattern to the community OO by Ward Cunningham and Kent Beck l 1995:Group of Four alias E.Gamma, R.Helm,R.Johnson and J.Vlissides : “Design Pattern:Elements of Reusable OO software”

5 What Is a Design Pattern  A design pattern is a descriptions of communicating objects and classes that are customized to solve a general design problem in a particular context  A pattern is made by four elements:  name name  problem problem  solution solution  consequences consequences

6 Name of Design Pattern  Describe a design problems and its solutions in a word or two  Used to talk about design pattern with our colleagues  Used in the documentation  Increase our design vocabulary  Have to be coherent and evocative

7 Problem l Describes when to apply the patterns l Explains the problem and its context l Sometimes include a list of conditions that must be met before it makes sense to apply the pattern l Have to occurs over and over again in our environment

8 Solution l Describes the elements that make up the design, their relationships, responsibilities and collaborations l Does not describe a concrete design or implementation l Has to be well proven in some projects

9 Consequences l Results and trade-offs of applying the pattern l Helpful for describe design decisions, for evaluating design alternatives l Benefits of applying a pattern l Impacts on a system’s flexibility,extensibility or portability

10 Description of Design Pattern l Pattern name and classification contains the essence of pattern succinctly Become part of your design vocabulary l Intent What does the pattern do ? What particular problem does it address ?

11 Description of Design Pattern Motivation l Motivation Illustrate a design problem and how the class and the object structures solve the problem l Applicability In which situations the pattern can be applied? How can you recognize these situations ?

12 Description of Design Pattern l Structure Graphical representation of the classes and their collaborations in the pattern l Participants Class Objects Responsibilities

13 Description of Design Pattern l Collaborations How the participants collaborate to carry out their responsibilities l Consequences How does the pattern support its objectives? What are the trade-offs and results of using the pattern?

14 Description of Design Pattern l Implementation l Sample Code l Known Uses Examples of the pattern found in real systems

15 Description of Design Pattern l Related Patterns What design patterns are closely related to this one? What are the important differences ?

16 By purpose and by scope l Creational patterns Creational patterns Creational patterns Abstract the instantiation process Make a system independent to its realization Class Creational use inheritance to vary the instantiated classes Object Creational delegate instantiation to an another object Classification of Design Pattern

17 Structural patterns Structural patterns l Structural patterns Structural patterns Class Structural patterns concern the aggregation of classes to form largest structures Object Structural pattern concern the aggregation of objects to form largest structures

18 Classification of Design Pattern Behavioral patterns Behavioral patterns l Behavioral patterns Behavioral patterns Concern with algorithms and assignment of responsibilities between objects Describe the patterns of communication between classes or objects Behavioral class pattern use inheritance to distribute behavior between classes Behavioral object pattern use object composition to distribute behavior between classes

19 Classification of design patterns ( a view) InterpreterAdapterFactory Method Visitor Strategy StateProxy ObserverFlyweight MementoFaçade MediatorDecoratorSingleton IteratorCompositePrototype CommandBridgeBuilder Chain of Responsibility AdapterAbstract Factory Template MethodBehavioralStructuralCreationalObjectClass purpose Scope

20 Creational Pattern l Singleton Singleton Ensure a class only has one instance Provide a global point of access to it l Abstract Factory: Provide an interface for creating families of related or dependent objects without specifying their concrete classes

21 Creational Pattern l Factory Method: Define an interface for creating an object but let subclasses decide which class to instantiate Lets a class defer instantiation to subclasses l Prototype Specify the kinds of objects to create using a prototypical instance Create new objects by copying this prototype

22 Creational Pattern l Builder: Separate the construction of a complex object from its representation so that the same construction process can create different representations

23 Structural Pattern l Composite Compose objects into tree structures to represent part-whole hierarchies Lets clients treat individual objects and compositions of objects uniformly l Decorator Decorator Attach additional responsibilities to an object dynamically Provide a flexible alternative to subclassing for extending functionality

24 Structural Pattern l Adapter: Convert the interface of a class into another interface clients expect Lets classes work together that couldn’t otherwise because of incompatible interfaces l Bridge: Decouple an abstraction from its implementation so that the two can vary independently

25 Structural Pattern l Façade Provide a unified interface to a set of interfaces in a subsystem Defines an higher-level interface that makes the system easier to use l Flyweight Use sharing to support large numbers of fine-grained objects efficiently

26 Structural Pattern l Proxy Provide a surrogate or placeholder for another object to control access to it

27 Behavioral Pattern l Iterator Iterator Provide a way to access the elements of an aggregate object without exposing its representation l Command Encapsulate a request as an object, thereby letting you parameterize clients with different requests

28 Behavioral Pattern l Interpreter Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language l Mediator Define an object that encapsulate how a set of objects interact Promotes loose coupling by keeping objects from referring to each other explicitly Lets you vary their interaction independently

29 Behavioral Pattern l Memento Capture and externalize an object’s internal state l Observer Define a one-to-many dependency between objects so when one of them change state all its dependents are updated automatically

30 Behavioral Pattern l State Allow an object to alter its behavior when its internal state changes The object will appear to change its class l Visitor Represent an operation to be performed on the elements of an object structure Lets you define a new operation without changing the classes of the elements on which operates

31 Behavioral Pattern l Strategy Define a family of algorithms Encapsulate each one Make them interchangeable Lets the algorithms vary independently from clients that use it l Chain of responsibilities Avoid coupling the sender of a request to its receiver by giving more then one object a chance to handle the request Chain the receiving objects and pass the request along the chain until an object handles it

32 Singleton Pattern l Motivation we need to have exactly only one instance for a class (ex. Printer spooler) Make the class itself responsible for keeping track of its sole instance The class provide a way to access the instance l Applicability There must be only one instance of a class accessible from a well- known point

33 Singleton Pattern l Structure Singleton Static Instance() SingletonOperation() GetSingletonData() Static uniqueInstance SingletonData Return uniqueInstance

34 Singleton Pattern l Participants Singleton class l Collaborations Access only through Singleton’s instance operation l Consequences Controlled access to sole instance Permits refinement of operation and representation More flexible than class operations

35 Example of Singleton use “Lotteria Algebrica” l We had to have only one instance for class Director. We simply solve our problem using Singleton Pattern Director Static Instance() Given(n_ticket:int):void Error():void Static UniqueInstance

36 Decorator Pattern l Motivation Add responsibilities to individual object not to an entire class conforming the interface of the component decorated

37 Decorator Pattern l Structure Component Operation() ConcreteComponent Operation() Decorator Operation() ConcreteDecoratorA Operation() AddedState ConcreteDecoratorB Operation() Addedbehavior

38 Decorator Pattern l Participants Component Define the interface for objects that can have responsibilities added to them dinamically Concrete Component Defines an object to which additional responsibilities can be attached Decorator Mantains a reference to a Component object and defines an interface that conforms to Component’s interface ConcreteDecorator Added responsibilities to the component

39 Decorator Pattern l Consequences More flexibility than static inheritance Avoids feature-laden classes high up in the hierarchy A decorator and its component are not identical Lots of little objects

40 Example of Decorator l Motivation If you have a TextView object that displays text in a Window TextView has no scroll bars by default TextView has no bord by default …

41 Example of Decorator l Structure aBorderDecorator component aScrollDecorator component aTextView

42 Example of Decorator l Structure VisualComponent Draw() TextView Draw() Decorator Draw() ScrollDecoratorBorderDecorator Draw() ScrollTo() ScrollPosition Draw() DrawBorder() BorderWidth

43 Iterator Pattern l Also know as Cursor l Motivation Provide more way to access to the elements of an aggregate List Count() Append(Element) Remove(Element) … ListIterator First() Next() IsDone() CurrentItem Index

44 Iterator Pattern l Applicability Access an aggregate object’s contents Support multiple traversals of aggregate objects Provide an uniform interface

45 Iterator Pattern l Structure Aggregate CreateIterator() ConcreteAggregate CreateIterator() Iterator First() Next() IsDone() CurrentItem() ConcreteIterator Return new ConcreteIterator(This) Client

46 Iterator Pattern l Participants Iterator Defines interfaces for accessing elements ConcreteIterator Implements the Iterator interface Keeps track of the current position in the traversal of the aggregate Aggregate Defines an interface for creating an Iterator object Concrete Aggregate Implements the Iterator creation interface Return an instance of ConcreteIterator

47 Iterator Pattern l Consequences Simplify the Aggregate interface More that one traversal can be pending on an aggregate Variations in the traversal of an aggregate

48 Patterns and Frameworks l Design patterns are more abstract than frameworks l Design patterns are smaller architectural elements than frameworks l Design patterns are less specialized than frameworks l Framework is executable software, design pattern represent knowledge about software l Frameworks are the physical realization of one or more software pattern solutions,pattern are instructions for how to implement those solutions Set of cooperating classes that make up reusable design for a specific class of software. Provides architectural guidance by partitioning the design into abstract classes and defining their responsibilities and collaborations. A developer customizes a framework to a particular application by subclassing and composing instances of framework classes.

49 Conclusions l At present, the software community is using pattern largely for software architecture and design l More recently the software community is using pattern also for software development processes and o organizations l Several object-oriented software design notations/methods have added support for the modeling and representation of design patterns

50 Bibliography For the pattern catalogue: l Erich Gamma, Richard Helm,Ralph Johnson,John Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. ADDISON-WESLEY 1995 For the pattern origin: l Cristopher Alexander. The Timeless Way of Building. Oxford Press 1979 For “Night Patterns”: l James O.Coplien,Douglas C.Schmidt.Pattern Languages of Program Design. ADDISON- WESLEY 1995

51 More Information Here you can find some example in Italian of design patterns. l http://www.ugolandini.net/PatternsHome.html http://www.ugolandini.net/PatternsHome.html Here you can find some general information about patterns l http://www.mokabyte.it/1998/10/pattern.htm http://www.mokabyte.it/1998/10/pattern.htm l http://www.c2.com http://www.c2.com A complete Web site about pattern l http://www.enteract.com/~bradapp/docs/patterns- intro.html http://www.enteract.com/~bradapp/docs/patterns- intro.html


Download ppt "Design Patterns: Elements of Reusable Object – Oriented Software Web Apps and Services."

Similar presentations


Ads by Google