Technieken van de Software Architectuur, VUB ‘98-’99, Part 41 Part 4: Design Patterns.

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Computer Graphics 02/10/09Lecture 41 Computer Graphics Lecture 3 Transformations.
 Recent researches show that predicative programming can be used to specify OO concepts including classes, objects, interfaces, methods, single and multiple.
Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
1 Structural Design Patterns - Neeraj Ray. 2 Structural Patterns - Overview n Adapter n Bridge n Composite n Decorator.
18-1 Verifying Object Behavior and Collaboration Role playing – the act of simulating object behavior and collaboration by acting out an object’s behaviors.
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
Plab – Tirgul 12 Design Patterns
CSE Software Engineering: Analysis and Design, 2005Lecture 8A.1 Software Engineering: Analysis and Design - CSE3308 Design and Analysis Patterns.
Observer Pattern Fall 2005 OOPD John Anthony. What is a Pattern? “Each pattern describes a problem which occurs over and over again in our environment,
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
(c) 2009 University of California, Irvine – André van der Hoek1June 13, 2015 – 21:42:16 Informatics 122 Software Design II Lecture 8 André van der Hoek.
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
BehavioralCmpE196G1 Behavioral Patterns Chain of Responsibility (requests through a chain of candidates) Command (encapsulates a request) Interpreter (grammar.
Design Patterns CS is not simply about programming
Design Patterns. What are design patterns? A general reusable solution to a commonly occurring problem. A description or template for how to solve a problem.
DESIGN PATTERNS Redesigning Applications And
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Design Patterns.
(c) 2010 University of California, Irvine – André van der Hoek1June 29, 2015 – 08:55:05 Informatics 122 Software Design II Lecture 8 André van der Hoek.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
(c) 2010 University of California, Irvine – André van der Hoek1July 16, 2015 – 13:45:31 Informatics 122 Software Design II Lecture 8 Nick Lopez Duplication.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
BDP Behavioral Pattern. BDP-2 Behavioral Patters Concerned with algorithms & assignment of responsibilities Patterns of Communication between Objects.
Design Patterns.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Forte Seminar, April Reusable Components Ready for Distribution Patrick Steyaert Programming Technology Lab Vrije Universiteit Brussel
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
CSE 403 Lecture 14 Design Patterns. Today’s educational objective Understand the basics of design patterns Be able to distinguish them from design approaches.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Behavioural Design Patterns Quote du jour: ECE450S – Software Engineering II I have not failed. I've just found 10,000 ways that won't work. - Thomas Edison.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
Behavioral Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Design Patterns Introduction
BEHAVIORAL PATTERNS 13-Sep-2012 Presenters Sanjeeb Kumar Nanda & Shankar Gogada.
Design Patterns Introduction “Patterns are discovered, not invented” Richard Helm.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
1 PSI: From Custom Developed Application to Domain-Specific Framework Wim Codenie, Wilfried Verachtert, Arlette Vercammen OO Partners Otto de Mentockplein.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
Design Patterns: MORE Examples
Chapter 10 Design Patterns.
Software Design Patterns
MPCS – Advanced java Programming
Introduction to Design Patterns
Design Patterns Lecture part 2.
Factory Patterns 1.
Introduction to Design Patterns
How to be a Good Developer
Design Patterns with C# (and Food!)
object oriented Principles of software design
Presented by Igor Ivković
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Informatics 122 Software Design II
Informatics 122 Software Design II
Presented by Igor Ivković
Presentation transcript:

Technieken van de Software Architectuur, VUB ‘98-’99, Part 41 Part 4: Design Patterns

Technieken van de Software Architectuur, VUB ‘98-’99, Part 42 Background 4Designing reusable software is difficult »Finding good objects and abstractions »Flexibility, Modularity, Elegance »Takes time to emerge, trial and error 4Successful designs exist 4How to describe recurring structures »Deja-Vu feeling, don’t reinvent the wheel, don’t reinvent the flat tire. 4Design Patterns: Elements of Reusable Object Oriented Software »E. Gamma R. Helm R. Johnson J. Vlissides

Technieken van de Software Architectuur, VUB ‘98-’99, Part 43 Design Patterns 4Design patterns capture successful solutions to recurring problems that arise during software construction 4Design patterns help to improve key software quality factors 4Design patterns support reuse of software architectures

Technieken van de Software Architectuur, VUB ‘98-’99, Part 44 A Design Pattern 4Describes a recurring design structure »Used twice rule »Names, abstracts from concrete designs »Identifies classes, collaborations, responsibilities »Applicability, trade-offs, consequences, language issues 4Is discovered, not invented

Technieken van de Software Architectuur, VUB ‘98-’99, Part 45 Practical Experience 4Design Patterns are based on practical solutions found in main-stream applications implemented in Smalltalk and C++ »Windowing Systems »CAD »Banking »Persistent Objects »Distributed Systems »...

Technieken van de Software Architectuur, VUB ‘98-’99, Part 46 Describing Design Patterns 4Pattern name and classification 4Intent 4Also Known As 4Motivation 4Applicability 4Structure 4Participants 4Collaborations 4Consequences 4Implementation 4Sample Code 4Known Uses 4Related Patterns

Technieken van de Software Architectuur, VUB ‘98-’99, Part 47 Catalogue of Design Patterns 4Purpose »Creational »Structural »Behavioural 4Scope »Class »Object

Technieken van de Software Architectuur, VUB ‘98-’99, Part 48 Structural Patterns 4Adaptor 4Bridge 4Composite 4Decorator 4Facade 4Flyweight 4Proxy

Technieken van de Software Architectuur, VUB ‘98-’99, Part 49 Behavioural Patterns 4Chain of Responsibility 4Command 4Interpreter 4Iterator 4Mediator 4Memento 4Observer 4State 4Strategy 4Template Method 4Visitor

Technieken van de Software Architectuur, VUB ‘98-’99, Part 410 Design Coverage 4Large Portion of design covered by patterns »Most classes play role in some patterns »Improved understanding 4Seductively simple to implement patterns 4You still have to write functionality »Common mistake is to think design patterns solve your problems

Technieken van de Software Architectuur, VUB ‘98-’99, Part 411 Abstract Factory

Technieken van de Software Architectuur, VUB ‘98-’99, Part 412 Abstract Factory 4Object Creational 4Intent: Provide an interface for creating families of objects without specifying the concrete classes 4Motivation: Creation of line segments, points,... in a drawing framework

Technieken van de Software Architectuur, VUB ‘98-’99, Part 413 Abstract Factory: Motivation ComponentFactory newLine() {abstract} newPoint() {abstract} GrayComponentFactory newLine() newPoint() ColorComponentFactory newLine() newPoint() ClientLineColorLineGrayLinePoint ColorPoint GrayPoint

Technieken van de Software Architectuur, VUB ‘98-’99, Part 414 Abstract Factory: Applicability 4Use the Abstract Factory Pattern when: »A system has to be independent of how its objects are created, composed and represented »Configuration with families of products is necessary »A family of products is designed to work together

Technieken van de Software Architectuur, VUB ‘98-’99, Part 415 Abstract Factory: Participants 4AbstractFactory (e.g. ComponentFactory) 4ConcreteFactory (e.g. ColorComponentFactory) 4AbstractProduct (e.g. Point) 4ConcreteProduct (e.g. ColorPoint) 4Client

Technieken van de Software Architectuur, VUB ‘98-’99, Part 416 Abstract Factory: Consequences 4It isolates clients from concrete classes 4Makes exchanging of product families easier 4It promotes consistency amongst products 4Supporting new kinds of products is difficult

Technieken van de Software Architectuur, VUB ‘98-’99, Part 417 Abstract Factory: Implementation 4Factories are best implemented as Singletons 4Creating the products »(1) Use a Factory Method for each product »(2) Initialize the concrete factory with a prototypical instance that can be copied 4Defining extensible factories »In AbstractFactory provide a parameter to identify the product to be created

Technieken van de Software Architectuur, VUB ‘98-’99, Part 418 Bridge

Technieken van de Software Architectuur, VUB ‘98-’99, Part 419 Example: Variations in storage InformixProgram... findPrograms... Program duration() productCode() broadcastitle (title: Title) static findPrograms (s:searchObject) : ProgramList... IngresProgram... findPrograms OracleProgram... findPrograms

Technieken van de Software Architectuur, VUB ‘98-’99, Part 420 The Original Persistency Layer 4Allow non DB experts to work on the application 4Migration to other DB's 4Be ready for OO databases Domain Model Persistency Layer Store Retrieve Hematomas

Technieken van de Software Architectuur, VUB ‘98-’99, Part 421 bcPIDProgramIDcontractPID Example Program contractPeriod broadcastPeriod Period from: 01/01/96, 00h00 to: 01/02/96, 00h00 from: 07/01/96, 20h00 to: 07/01/96, 22h00 Period ProgramTable: PeriodTable: PeriodIDfromDatefromHourtoDatetoHour foreign key

Technieken van de Software Architectuur, VUB ‘98-’99, Part 422 Solution: Bridge Pattern 4Intent: Decouple an abstraction from its implementation so that the two can vary independently 4Motivation: Window Implementations

Technieken van de Software Architectuur, VUB ‘98-’99, Part 423 Bridge: Motivation Window DrawText() DrawRect WindowImp DrawText() DrawRect TransientWindow DrawCloseBox IconWindow DrawBorder() Window95Imp DrawText() DrawRect XWindowImp DrawText() DrawRect Imp

Technieken van de Software Architectuur, VUB ‘98-’99, Part 424 Bridge: Applicability 4Use the Bridge Pattern to »Avoid a permanent binding between an abstraction and its implementation »Both the abstractions and their implementations should be extensible by subclassing »To avoid proliferation of classes Separation of Concerns

Technieken van de Software Architectuur, VUB ‘98-’99, Part 425 Bridge: Structure Abstraction Operation() Implementor OperationImp() imp RefinedAbstraction ConcreteImpB OperationImp() ConcreteImpA OperationImp() Client Bridge Participants

Technieken van de Software Architectuur, VUB ‘98-’99, Part 426 Bridge: Consequences 4Decoupling interface and implementation 4Improved extensibility 4Hiding implementation details from clients

Technieken van de Software Architectuur, VUB ‘98-’99, Part 427 Implementation Object Knows how to map itself to a relational database Implementation Object Knows how to map itself to a relational database The Bridge Architecture A B C+D Conceptual Object Contains business rules

Technieken van de Software Architectuur, VUB ‘98-’99, Part 428 DomainObject store() initialize() storage () The Bridge Architecture StorageObject... Program title(t:Title) BasicStorageAdaptorStorage FlattenedStorage HierarchyStorage Mapping Strategies storagedomain

Technieken van de Software Architectuur, VUB ‘98-’99, Part 429 Bridge: Basic Mappings DomainObject store() initialize()... StorageObject Firm name(s:String)... BasicStorage FirmStorage name:String name (s:String)... name [name] name addr... PSIFirmTable

Technieken van de Software Architectuur, VUB ‘98-’99, Part 430 Bridge: Basic Mappings 4A commercially available framework is used for the basic mappings (Object Lens) 4The abstract classes contain behavior for querying, retrieval, etc. of data 4The basic mappings are database independent

Technieken van de Software Architectuur, VUB ‘98-’99, Part 431 Bridge: Mappings of Classes A B C C B A+B+C A FlattenedStorage HierarchyStorage

Technieken van de Software Architectuur, VUB ‘98-’99, Part 432 FlattenedStorage Bridge: FlattenedStorage DomainObject Contract SalesContractPurchaseContract StorageObject BasicStorage ContractStorage date:String date (s:String)... name addr classID

Technieken van de Software Architectuur, VUB ‘98-’99, Part 433 BProgramStorage Bridge: HierarchyStorage DomainObject Program Episode StorageObject BasicStorage BEpisodeStorage HierarchyStorage ProgramStorage EpisodeStorage programPart episodePart

Technieken van de Software Architectuur, VUB ‘98-’99, Part 434 Bridge: Adaptor Mapping Program broadcastPeriod contractPeriod Period from: 01/01/96, 00h00 to: 01/02/96, 00h00 from: 07/01/96, 20h00 to: 07/01/96, 22h00 Period ProgramTable bcFromDate bcFromTime bcToDate bcToTime cntrFromDate cntrFromTime... bcFromDate bcFromTime bcToDate bcToTime cntrFromDate cntrFromTime cntrToDate cntrToTime ProgramStorage Conceptual ObjectsImplementation Objects BCPeriodStorage Database toDate[toDate] toDate[bcToDate]

Technieken van de Software Architectuur, VUB ‘98-’99, Part 435 Bridge: Adaptor Mapping DomainObject store() initialize()... StorageObject Period from():Time to(): Time BasicStorage ProgramStorage bcFrom:Date bcTo:Date AdaptorStorage BCPeriodStorage from():Time to():Time Adaptor design pattern to [bcTo] adaptee

Technieken van de Software Architectuur, VUB ‘98-’99, Part 436 Adaptors Period to():Time from(): Time includesTime(t:Time):Boolean merge(p:Period):Period PeriodAdaptor PeriodImpl to:Time from: Time to():Time from(): Time Period to():Time from(): Time includesTime(t:Time):Boolean merge(p:Period):Period

Technieken van de Software Architectuur, VUB ‘98-’99, Part 437 Observer

Technieken van de Software Architectuur, VUB ‘98-’99, Part 438 Observer 4Intent: Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. 15,20,40 4Motivation: Maintain consistency between objects without a tight coupling that reduces reusability.

Technieken van de Software Architectuur, VUB ‘98-’99, Part 439 Observer : Applicability 4Use Observer when »an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently. »a change to one object requires changing others, and you don’t know how many objects need to be changed »an object should be able to notify other objects without making assumptions about who these objects are. Separation of Concerns

Technieken van de Software Architectuur, VUB ‘98-’99, Part 440 Observer : Structure Subject attach(Observer) dettach(Observer) Notify() Observer update() ConcreteObserver observerState update() state ConcreteSubject subjectState getState() setState() forall o in observers o update return subjectState observerState= subject subjectState Observer Participants

Technieken van de Software Architectuur, VUB ‘98-’99, Part 441 Observer : Consequences 4abstract coupling between subject and observer 4support for broadcast communication 4unexpected updates

Technieken van de Software Architectuur, VUB ‘98-’99, Part 442 State

Technieken van de Software Architectuur, VUB ‘98-’99, Part 443 State 4Object Behavioral 4Intent: Allow an object to alter its behavior when its internal state changes. The object will appear to change its class 4Motivation: Network connection

Technieken van de Software Architectuur, VUB ‘98-’99, Part 444 State: Motivation TCPConnection open () close() TCPState clone() TCPListen open() close() TCPClosed open() close() state TCPEstablished open() close() state close()

Technieken van de Software Architectuur, VUB ‘98-’99, Part 445 State : Applicability 4Use State »when an object’s behavior depends on its state and it must chaneg its behavior at runtime »when operations have large conditional statements that depend on the state of the objects

Technieken van de Software Architectuur, VUB ‘98-’99, Part 446 State : Participants 4Context (e.g. TCPConnection) 4State (e.g. TCPState) 4ConcreteState (subclasses of State)

Technieken van de Software Architectuur, VUB ‘98-’99, Part 447 State : Structure Context request() State handle() TCPListen handle() TCPClosed handle() state TCPEstablished handle() state handle()

Technieken van de Software Architectuur, VUB ‘98-’99, Part 448 State : Consequences 4separates state-specific behavior from general behavior 4Makes state-transitions explicit 4State objects can be shared

Technieken van de Software Architectuur, VUB ‘98-’99, Part 449 Composite

Technieken van de Software Architectuur, VUB ‘98-’99, Part 450 BUT? How to combine ? - multiple inheritance - mixin classes + Node LoggingNode WorkstationPrintserver Node Separate discussion (design patterns)

Technieken van de Software Architectuur, VUB ‘98-’99, Part Program duration() productCode() broadcastitle (title: Title) static findPrograms (s:searchObject) : ProgramList... Example: Variations in the domain Series... Episode...

Technieken van de Software Architectuur, VUB ‘98-’99, Part 452 Example: Variations in the domain ComposedProgram duration () Program duration() broadcastitle (title: Title) static findPrograms (s:searchObject) : ProgramList... ProgramSlice duration ()

Technieken van de Software Architectuur, VUB ‘98-’99, Part 453 Combining variations 4Duplication of behavior »Not a satisfying solution »Proliferation of versions 4Concentrate behaviour »Not a satisfying solution »Overfeaturing ProgramSlice Program Episode EpisodeSlice Program isSlice...

Technieken van de Software Architectuur, VUB ‘98-’99, Part 454 Composite Programs ComposedProgram duration () Program duration()... SeriesEpisode duration [duration]

Technieken van de Software Architectuur, VUB ‘98-’99, Part 455 A Solution Program duration()... SeriesEpisode Structure duration()... Composed duration() Atomic duration() Sliced duration() concretisation parts duration [duration] Separation of Concerns State design pattern Composite design pattern structure

Technieken van de Software Architectuur, VUB ‘98-’99, Part 456 Decorator

Technieken van de Software Architectuur, VUB ‘98-’99, Part 457 Decorator: Participants 4Component (e.g. VisualComponent) 4ConcreteComponent (e.g. TextView) 4Decorator (e.g. Decorator) 4ConcreteDecorator (e.g. BorderDecorator)

Technieken van de Software Architectuur, VUB ‘98-’99, Part 458 Decorator: Structure Component Operation() ConcreteComponent Operation() Decorator Operation() component ConcreteDecoratorA added state Operation() added behaviour ConcreteDecoratorB added state Operation() added behaviour component operation super operation added behaviour

Technieken van de Software Architectuur, VUB ‘98-’99, Part 459 Decorator: Consequences 4More flexible than static inheritance. 4Avoids classes with a lot of features »Refactoring method ! »Lots of little objects »Avoids duplication of features 4Object identity can be a problem

Technieken van de Software Architectuur, VUB ‘98-’99, Part 460 Decorator: Participants 4Component (e.g. VisualComponent) 4ConcreteComponent (e.g. TextView) 4Decorator (e.g. Decorator) 4ConcreteDecorator (e.g. BorderDecorator)

Technieken van de Software Architectuur, VUB ‘98-’99, Part 461 Decorator: Structure Component Operation() ConcreteComponent Operation() Decorator Operation() component ConcreteDecoratorA added state Operation() added behaviour ConcreteDecoratorB added state Operation() added behaviour component operation super operation added behaviour

Technieken van de Software Architectuur, VUB ‘98-’99, Part 462 Decorator: Consequences 4More flexible than static inheritance. 4Avoids classes with a lot of features »Refactoring method ! »Lots of little objects »Avoids duplication of features 4Object identity can be a problem

Technieken van de Software Architectuur, VUB ‘98-’99, Part 463 Design Patterns in Practice Architectural Layers Integration Redundancy Data Warehousing

Technieken van de Software Architectuur, VUB ‘98-’99, Part 464 Firstname Lastname Age Person Editor Person Reusable Objects/Components

Technieken van de Software Architectuur, VUB ‘98-’99, Part 465 Firstname Lastname Age Person Editor Person Separation of Concerns

Technieken van de Software Architectuur, VUB ‘98-’99, Part 466 Drawing Editor Firstname Lastname Age Person Editor License Brand Age Car Editor Person Car Drawing Layered Architecture

Technieken van de Software Architectuur, VUB ‘98-’99, Part 467 Bridge: Integration PSI PSI DB Other Application External DB Bridge

Technieken van de Software Architectuur, VUB ‘98-’99, Part 468 Controlling Redundancy FirmID Firm Name Title Program Editor StorageObject BasicStorage FirmStorage name:String name (s:String) id: Sring id (s:String) ProgramStorage firmName:String firmName (s:String) firmId: Sring firmId (s:String)... Updates programStorage if name or id changes

Technieken van de Software Architectuur, VUB ‘98-’99, Part 469 Data Warehousing: CASE Number Amount Owner Account Editor Application RDBMS Mainframe Application for account management CICS Transactions Mirrored DB...

Technieken van de Software Architectuur, VUB ‘98-’99, Part 470 AccountStorage amount(): Integer owner(): Owner... Data Warehousing: CASE Account amount(): Integer owner(): Owner... storage Bridge Number Amount Owner Account Editor

Technieken van de Software Architectuur, VUB ‘98-’99, Part 471 AccountStorage amount(): Integer owner(): Owner... Data Warehousing: CASE Account amount(): Integer owner(): Owner... storage Bridge Number Amount Owner Account Editor Transaction CICS CICS1234 CICS1235 Adaptor

Technieken van de Software Architectuur, VUB ‘98-’99, Part 472 AccountStorage amount(): Integer owner(): Owner... Data Warehousing: CASE Account amount(): Integer owner(): Owner... storage Bridge Number Amount Owner Account Editor Transaction CICS CICS1234 CICS1235 Adaptor CICSAccountAmount set(amount: Integer) get(): Integer Facade

Technieken van de Software Architectuur, VUB ‘98-’99, Part 473 Data Warehousing Account amount(): Integer owner(): Owner... storage AccountStorage amount(): Integer owner(): Owner... Transaction CICS CICS1234 CICS1235 CICSAccountAmount set(amount: Integer) get(): Integer Facade Adaptor AccountBasicStorage Bridge Number Amount Owner Account Editor

Technieken van de Software Architectuur, VUB ‘98-’99, Part 474 Bridge: Summary 4Provides a clean separation between domain and storage 4Allows easy integration with other systems 4Various mappings had to be included »NOT part of the Bridge Design Pattern