Banaras Hindu University - INFLIBNET...

Preview:

Citation preview

Banaras Hindu University

A Course on

Software Reuse by Design Patterns and Frameworks

by

Dr. Manjari Gupta Department of Computer Science

Banaras Hindu University

Lecture 4

Introduction to Design Patterns

∗ During the late 1970s ∗ Christopher Alexander ∗ different structures that were designed to solve the

same problem ∗ similarities among designs that were of high quality-

towns and buildings ∗ a context, a set of forces and a solution

∗ a set of correlated patterns- pattern language

Architectural patterns

∗ key to manage complexity ∗ One of the current successful abstractions

∗ design pattern ∗ birth of patterns in software field

∗ by Ward Canningham and Kent Beck ∗ first five patterns dealt with the design of user

interfaces ∗ concept of patterns is being adapted to many other

fields

Abstraction

∗ description of a proven (successful or efficient) solution to a recurring problem within a context

∗ informal descriptions of tested solutions to recurring problems ∗ a pattern can be reused as a building block for better software

construction and designer communication ∗ Properties inherent in the definition of patterns

∗ determine if the description of a design is pattern or not. ∗ artifacts of software reusability ∗ published mostly within collections or catalogs. ∗ well-known and widely used

∗ Gang-of-Four (GoF) patterns [Gamma95] and J2EE patterns

Design Pattern

∗ describes solution to a recurring problem in software design phase.

∗ descriptions of recurring pattern of communicating classes that form a common solution to a common design problem.

∗ describes when it applies, whether it can be applied in view of other design constraints, and the consequences and trade-offs of its use

Design Pattern

∗ make object oriented design more flexible, elegant and ultimately reusable

∗ A designer can apply them immediately to design problems

∗ help designers reuse successful designs ∗ It captures experts’ design decisions

Design Patterns

∗ improve the quality of software e.g. ∗ reusability, extensibility, and maintainability

∗ reflect the designers’ intents ∗ useful in both development of new, and comprehension of

existing object-oriented designs ∗ Patterns capture previous design experiences and make it

available to other designers ∗ Form a more flexible foundation for reuse

Importance of design patterns

∗ also serve as a communication medium among software designers

∗ promising technique for achieving widespread reuse of software architectures ∗ capture static and dynamic structures and

collaborations of components ∗ aid the development of other reusable artefacts

Importance of design patterns

∗ have common template that make it easy to learn and understand them.

∗ has four essential elements: ∗ The name of the pattern ∗ The Problem and its context ∗ The solution ∗ Consequences

∗ for different domains different template are needed to describe solution more elegantly in that domain

Elements of design patterns

∗ Model: stores the application’s state. ∗ View: interprets data in the model and presents it to

the user. ∗ Controller: processes user input, and either updates

the model or displays a new view. ∗ Originally designed for graphical environments ∗ adapted for use in other areas of programming

Model-View-Controller (MVC) Pattern

Overview of the MVC Pattern [Crawford06]

Controller

Views Model

+updateModel(): +chooseView(): +…():

View

User controls

Model

State Data

updates uses

Chooses

Sends user input

*

* 1

1

∗ each component is simple and self-contained, with well-defined interfaces

∗ components can vary independently and are therefore easier to share and reuse

∗ used in ET++ framework ∗ not suitable for simple user interface toolbox

components

MVC Pattern

∗ encapsulates possible variations of a given algorithm ∗ allows the system to invoke the more appropriate

algorithm depending on a given context

Strategy design pattern

Strategy design pattern Cont…

Explicit representation of the pattern hot-spots

Instantiation diagram for strategy pattern

∗ provides a uniform way to create object trees that represent part-whole hierarchies.

∗ allows new kinds of components to be added to the system without disturbing the behavior of the composite objects

Composite design pattern

Composite design pattern

Highlighting the configuration step

Composite pattern instantiation diagram

∗ Different categorization schemes ∗ Purpose

∗ creational, structural, or behavioral ∗ Scope

∗ whether the pattern applies primarily to classes or to objects.

Design patterns’ classification

• relationship between patterns ∗ Pattern X uses pattern Y in its solution, ∗ Pattern X is similar to pattern Y, and ∗ Pattern X can be combined with pattern Y.

Zimmer Classification of Design Pattern [hammouda04(b)]

Zimmer Classification of Design Pattern [hammouda04(b)]

∗ method calls involved in the GoF patterns were classifiable by three orthogonal properties ∗ The relationship of the target object instance to the

calling object instance. ∗ The relationship of the target object’s type to the calling

object’s type ∗ The relationship between the method signatures of the

caller and callee.

Based on involved method calls

Classification system for design patterns [Gamma93]

∗ informal textual notation; ∗ formal textual notation, that is, a formalism or a

programming language; ∗ graphic notation.

Specification of Design patterns

∗ to better represent (to explicitly represent pattern hotspots) configuration patterns.

∗ explicitly represents pattern hotspots ∗ The representation of configuration patterns are enhanced by:

∗ explicitly representing the pattern instantiation, and ∗ being abstract enough to simplify the diagrams and allow several

implementation approaches to be used.

Extension to the UML design notation [Fontoura]

∗ Changing the class diagrams to explicitly identify pattern hot-spots and application classes;

∗ Defining instantiation diagrams, which represent the pattern instantiation process.

∗ a new stereotype- Application class ∗ two new tagged values- variable and extensible ∗ incomplete constraint

UML Extension

Highlighting the configuration step

Composite pattern instantiation diagram

Recommended