Introduction to Patterns and Many problems recur. Design Patterns - - PDF document

introduction to patterns and
SMART_READER_LITE
LIVE PREVIEW

Introduction to Patterns and Many problems recur. Design Patterns - - PDF document

Observations Engineering=Problem Solving Introduction to Patterns and Many problems recur. Design Patterns Many problems have the same (or at least similar) solution structure. Exact solution is dependent on the context A more


slide-1
SLIDE 1

1

Introduction to Patterns and Design Patterns

Eunjee Song Deign Patterns Intro-1

Eunjee Song

  • Dept. of Computer Science

Baylor University

Some slides adapted from slides by R. France and B. Tekinerdogan

Observations

 Engineering=Problem Solving  Many problems recur.  Many problems have the same (or at least similar)

solution structure.

 Exact solution is dependent on the context

Eunjee Song Deign Patterns Intro-2

 A more experienced person can solve new

problems faster and better.

 Fundamental to any engineering discipline (even

any science): a common vocabulary for expressing its concepts, and a language for relating them together.

Electrical Engineering Patterns

Eunjee Song Deign Patterns Intro-3

Mechanical Engineering Patterns

Eunjee Song Deign Patterns Intro-4

Chemical Engineering Patterns

Eunjee Song Deign Patterns Intro-5

Software Engineering Patterns

Eunjee Song Deign Patterns Intro-6

slide-2
SLIDE 2

2

 Timeless Way of Building (Oxford University

Press, 1970)

Origin of the term "pattern”

Eunjee Song Deign Patterns Intro-7

Work on software development patterns stemmed from work on patterns from building architecture carried out by Christopher Alexander.

Pattern: Problem-Solution-Context

Eunjee Song Deign Patterns Intro-8

What are software patterns?

 Patterns are intended to capture the best

available software development experiences in the form of problem-solution pairs.

 A pattern outlines solutions to a family of

software development problems in a particular

Eunjee Song Deign Patterns Intro-9

software development problems in a particular context.

 A pattern outlines a process for transforming

problems targeted by the problem to solutions characterized by the pattern.

 Abstraction,  Encapsulation  Information hiding  Separation of concerns

Patterns Solve Software Structural Problems like...

Eunjee Song Deign Patterns Intro-10

 Separation of concerns  Coupling and cohesion  Separation of interface and

implementation

 Single point of reference  Divide and conquer  Changeability  Interoperability  Efficiency

Patterns Solve Non-functional Problems like...

Eunjee Song Deign Patterns Intro-11

 Reliability  Testability  Reusability

Pattern Types

Requirements Patterns: Characterize families of requirements for a family of applications

 e.g., checkin-checkout pattern: can be used to obtain

requirements for library systems, car rental systems, video systems, etc.

Architectural Patterns: Characterize families of architectures

 e.g., Broker pattern: can be used to create distributed

systems in which location of resources and services is

Eunjee Song Deign Patterns Intro-12

systems in which location of resources and services is transparent (e.g., the WWW)

 Other examples: MVC, Pipe-and-Filter, Multi-Tiered 

Design Patterns: Characterize families of low-level design solutions

 Examples: Gang of Four (GoF) patterns 

Programming idioms: Characterize programming language specific solutions

slide-3
SLIDE 3

3

Example of an Architectural Pattern - Model-View-Controller (MVC) Pattern

 Context: Developing user-interfaces (UIs )  Problem: How to create a UI that’s resilient to

changes such as changes in look-and-feel windowing system, changes in functionality.

Eunjee Song Deign Patterns Intro-13

 Factors: changes to UI should be easy and possible

at run-time; adapting or porting the UI should not impact the implementation of the core functionality.

MVC Solution Outline: Split Application into 3 Areas:

 The Model component: encapsulates core

functionality; independent of input/output representations and behavior.

 The View components: displays data from the

d l t th b lti l i

Eunjee Song Deign Patterns Intro-14

model component; there can be multiple views for a single model component.

 The Controller components: each view is

associated with a controller that handles inputs; the user interacts with the system via the controller components.

Patterns Summary

 A pattern addresses a recurring software

development problem that arises in a particular context, and outlines a solution for it.

 A pattern captures ‘best practices’ in software

development (the intention! ).

 A pattern should be based on actual experiences in Eunjee Song Deign Patterns Intro-15

industry

 Patterns provide a common vocabulary for, and

understanding of ‘best practices’.

 Developers can refer to a pattern by name (e.g., the

Adapter pattern) and others familiar with the pattern will not need further description

Patterns, Architectures & Frameworks

 There can be confusion between patterns,

architectures and frameworks.

 Architectures model software structure at

the highest possible level, and give the

Eunjee Song Deign Patterns Intro-16

  • verall system view. An architecture can use

many different patterns in different components

 Patterns are more like small-scale or local

architectures for architectural components

  • r sub-components

Patterns, Architectures & Frameworks (cont...)

Eunjee Song Deign Patterns Intro-17

 Frameworks are partially completed

software systems that may be targeted at a particular type of application. These are tailored by completing the unfinished components.

Summary of Differences

 Patterns are more general and abstract than

  • frameworks. A pattern is a description of a

problem-solution pair, not a solution (or problem) itself.

 A pattern cannot be directly implemented. An

Eunjee Song Deign Patterns Intro-18

implementation is an example of a pattern.

 Patterns are more primitive than frameworks. A

framework can employ several patterns.

slide-4
SLIDE 4

4

Gang of 4 (GoF) Design Pattern Classification

Purpose categories described in “Design Patterns:…” by Gamma, Helm, Johnson and Vlissides; Addison-Wesley

 Creational 

Patterns that can be used to make object creation more flexible (e.g., Abstract Factory) or restrict creation activities (e.g., Singleton). H l k t i d d t f h bj t t d

Eunjee Song Deign Patterns Intro-19 

Help make a system independent of how objects are created, composed, and represented (i.e., allows one to vary how

  • bjects are created, composed, and represented)

 Structural 

Concerned with creating flexible mechanisms for composing

  • bjects to form larger of structures

 Behavioral 

Concerned with creating flexible algorithms and with assigning responsibilities to classes

Scope Criterion

Scope determines whether a pattern applies to classes or objects

 Classes

 class relations  inheritance structures (static-fixed at compile-time)  examples: Factory Method (creation); Adapter

( t t l) I t t T l t M th d (b h i l)

Eunjee Song Deign Patterns Intro-20

(structural); Interpreter, Template Method (behavioral)

 Objects

 object relations.  dynamic (can be changed at run-time)  examples: Abstract Factory, Builder, Singleton

(creation); Adaptor, Bridge, Facade (structural); Iterator, Observer, Visitor (behavioral)

Catalog of 23 Design Patterns by GoF

Purpose Creational Structural Behavioral Sco

Class

Factory Method Adapter (class) Interpreter Template Method Abstract Factory* Prototype Builder Adapter (object)* Bridge* Composite * Chain of Responsibility Command* Iterator *

Eunjee Song Deign Patterns Intro-21

  • pe

Object

Singleton Decorator* Facade Flyweight Proxy Mediator Observer* State Strategy * Visitor*

Scope: domain over which a pattern applies, Purpose: reflects what a pattern does

* : patterns to be covered with a Document Editor (Lexi) Example and/or an

Asteroids game example  Facade Pattern: Interfacing to subsystems  Observer Pattern: Maintain consistency across

redundant state, also called Publisher-Subscriber

 Composite Pattern: Modeling of dynamic aggregates  Strategy Pattern: Interface to a task implemented by

different algorithms Ad t P tt I t f t ld t (l

Eunjee Song

 Adapter Pattern: Interface to old systems (legacy

systems)

 Bridge Pattern: Interfacing to existing and future

systems

 Proxy Pattern: Reduces the cost of accessing

  • bjects

Deign Patterns Intro-22

Why Study Design Patterns?

 Reuse existing, high-quality solutions to

commonly recurring problems

 Establish common terminology to improve

communications within teams Shift th l l f thi ki t hi h

Eunjee Song Deign Patterns Intro-23

 Shift the level of thinking to a higher

perspective (i.e., help us see the forest AND the trees)

 Decide whether I have the right design, not

just one that works.

Why Study Design Patterns? (cont…)

 Improve individual learning and team learning  Improve the modification of model/code  Facilitate adoption of improved design

alternatives even when patterns are not used

Eunjee Song Deign Patterns Intro-24

alternatives, even when patterns are not used explicitly