design patterns trends and case study john hurst june 2005

26
Design Patterns Trends and Case Study John Hurst June 2005

Upload: philippa-terry

Post on 26-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Design Patterns Trends and Case Study John Hurst June 2005

Design Patterns

Trends and Case Study

John HurstJune 2005

Page 2: Design Patterns Trends and Case Study John Hurst June 2005

Overview

• Software Patterns• Design Patterns• Topics• Case Study / Examples

Page 3: Design Patterns Trends and Case Study John Hurst June 2005

Introduction

• Christopher Alexander– A Pattern Language: Towns, Buildings, Construction

(1977)– A Timeless Way of Building (1979)

• “Gang of Four” (Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides)– Design Patterns (1995)

• Buschmann et al– Pattern Oriented Software Construction (1996)

Page 4: Design Patterns Trends and Case Study John Hurst June 2005

Key Idea

• A Software Pattern is:– A solution– To a problem– In a context– With consequences

• A Software Pattern has a name and a vocabulary.

Page 5: Design Patterns Trends and Case Study John Hurst June 2005

Pattern Languages

• Intent• Also Known As• Motivation• Applicability• Structure• Participants

• Collaborations• Consequences• Implementation• Known Uses• Related Patterns

Page 6: Design Patterns Trends and Case Study John Hurst June 2005

OO Design Principles

• Code to interfaces• Prefer composition to inheritance• Encapsulate what varies

Page 7: Design Patterns Trends and Case Study John Hurst June 2005

Benefits

• Improves thinking about OO design– New designs– Existing designs– Helps us realise the benefits of OO

• Reuse of solutions to common problems– Catalogs

• Communication tool– Common vocabulary

Page 8: Design Patterns Trends and Case Study John Hurst June 2005

Example: Iterator

• Intent: – Provide a way to access the elements of

an aggregate object sequentially without exposing its underlying representation

Page 9: Design Patterns Trends and Case Study John Hurst June 2005

Example: Decorator

• Intent: – Attach additional responsibilities to an object

dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.

+Operation()

ConcreteComponent

+Operation()

Decorator-component

1

*

+Operation()

-addedState

ConcreteDecoratorA

+Operation()+AddedBehaviour()

ConcreteDecoratorB

component->Operation()

Decorator::Operation();AddedBehaviour()'

+Operation()

Component

Page 10: Design Patterns Trends and Case Study John Hurst June 2005

Application of Decorator

• Apache Commons DBCP (Database Connection Pooling)

+createStatement()+prepareStatement()+prepareCall()+commit()+rollback()+close()

«interface»Connection

+createStatement()+prepareStatement()+prepareCall()+commit()+rollback()+close()

-_conn

DelegatingConnection

1

*

+close()

-_pool

PoolableConnection

+prepareStatement()+close()

-_pstmtPool

PoolingConnection

Page 11: Design Patterns Trends and Case Study John Hurst June 2005

Patterns Landscape

• Architectural Patterns• Analysis Patterns• Design Patterns

Page 12: Design Patterns Trends and Case Study John Hurst June 2005

“Platform Patterns”

• J2EE Core Patterns• MS Building Blocks

• Contrast with PEAA

Page 13: Design Patterns Trends and Case Study John Hurst June 2005

Antipatterns

• Examples– Big Ball Of Mud– Copy and Paste Programming– Magic Container– Tower of Voodoo

Page 14: Design Patterns Trends and Case Study John Hurst June 2005

Broken Patterns

• Double checked locking• “Deprecated” Patterns:

– Factory Method (due to confusion over what it means)

– Bridge– Flyweight– Interpreter

Page 15: Design Patterns Trends and Case Study John Hurst June 2005

Specialised Fields

• Real-time• Concurrency• Enterprise• Messaging• Analysis

Page 16: Design Patterns Trends and Case Study John Hurst June 2005

Refactoring to Patterns

• Remove duplicate code• Simplify logic• Communicate intention• Increase flexibility

Page 17: Design Patterns Trends and Case Study John Hurst June 2005

Pattern Happy

Page 18: Design Patterns Trends and Case Study John Hurst June 2005

Patterns with Programming Languages

• Strategy– C++ templates: static type checking– Java interfaces and objects: runtime

configuration– Ruby/Smalltalk blocks: idiomatic usage

Page 19: Design Patterns Trends and Case Study John Hurst June 2005

Case Study: HHRDM

• Design Patterns• Architectural Patterns• Analysis Patterns

Page 20: Design Patterns Trends and Case Study John Hurst June 2005

Design Patterns

• Abstract Factory• Template Method• Strategy• Façade• Proxy

Page 21: Design Patterns Trends and Case Study John Hurst June 2005

Architectural Patterns

• Layering• Data Access Patterns• Domain Model• Service Façade

Page 22: Design Patterns Trends and Case Study John Hurst June 2005

Analysis Patterns

• Temporal Patterns– Effectivity– Snapshot– Temporal Object– Temporal Property– Audit Trail– Bitemporal Model

Page 23: Design Patterns Trends and Case Study John Hurst June 2005

References• Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides

Design Patterns: Elements of Reusable Object-Oriented Software – Addison-Wesley 1995

• Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad, Michael Stal Pattern-Oriented Software Architecture Wiley 1996

• Martin Fowler Patterns of Enterprise Application Architecture – Addison-Wesley 2002

• Martin Fowler Refactoring – Addison-Wesley 2000• Martin Fowler Analysis Patterns – Addison Wesley 1996• Gregor Hohpe, Bobby Woolfe Patterns of Enterprise

Application Integration – Addison-Wesley 2003• Joshua Kerievsky Refactoring to Patterns – Addison-Wesley

2004• Deepak Alur, John Crupi, Dan Malks Core J2EE Patterns (2nd

Ed) – Addison-Wesley 2003

Page 24: Design Patterns Trends and Case Study John Hurst June 2005

Web Sites

• Martin Fowler website http://www.martinfowler.com

• Portland Pattern Repository http://c2.com/cgi/wiki

• TheServerSide http://www.theserverside.com

• Microsoft Patterns and Practices http://msdn.microsoft.com/architecture/patterns/

Page 25: Design Patterns Trends and Case Study John Hurst June 2005

Relationships and Similarities

+Request()

«interface»Subject

+Request()

Proxy

+Request()

RealSubject ...realSubject->Request()...

+Operation()

ConcreteComponent

+Operation()

Decorator-component

+Operation()

-addedState

ConcreteDecoratorA

+Operation()+AddedBehaviour()

ConcreteDecoratorB

component->Operation()

Decorator::Operation();AddedBehaviour()'

+Operation()

«interface»Component

Proxy Decorator

Many patterns look similar structurally, but have different intent

Page 26: Design Patterns Trends and Case Study John Hurst June 2005

The Agile Manifesto

• Preferences:– Inidividuals and interactions over

processes and tools– Working software over comprehensive

documentation– Customer collaboration over contract

negotiation– Responding to change over following a

plan