Applying the Principles

Slides:



Advertisements
Similar presentations
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Advertisements

Façade Pattern Jeff Schott CS590L Spring What is a façade? 1) The principal face or front of a building 2) A false, superficial, or artificial appearance.
Prototype Pattern Intent:
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
A Behavior Object Pattern
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Facade Introduction. Intent Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the.
Structural Design Patterns
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IV Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Structural Patterns1 Nour El Kadri SEG 3202 Software Design and Architecture Notes based on U of T Design Patterns class.
FacadeDesign Pattern Provide a unified interface to a set of interfaces in a subsystem. Defines a high level interface that makes the subsystem easier.
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
The HotCiv GUI Instantiating the MiniDraw Framework.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
1 Advanced Object-oriented Design – Principles and Patterns Structural Design Patterns.
HotCiv Project Starting up!. Henrik Bærbak Christensen2 HotCiv = Agile development Iterations of –product development –learning increments.
Deriving State…...and an example of combining behaviour.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
Multi Dimensional Variance: How to make ultra flexible software!
Applying the Principles Two Examples. Example 1 New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests...
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
MiniDraw Introducing a Framework... and a few patterns.
Patterns are Roles What patterns are and what not…
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Deriving Abstract Factory Loosening the coupling when creating objects...
Strategy in 15 minutes... derived from the principles.
CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Hints - Mandatory 5 Blackbox Testing Pattern Hunting.
Instantiating the MiniDraw Framework
Introducing a Framework ... and a few patterns
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Presented by FACADE PATTERN
Design Patterns: MORE Examples
Mediator Design Pattern
MPCS – Advanced java Programming
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Chapter 12: Collaboration Diagram - PART2
CS 350 – Software Design The Strategy Pattern – Chapter 9
HotCiv Project Starting up!.
Mandatory 1 / AlphaCiv … Traps to be aware of ….
Compositional Design Principles
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
object oriented Principles of software design
Decorator Design Pattern
Decorator Pattern Intent
Informatics 122 Software Design II
Object Oriented Design Patterns - Structural Patterns
Decorator Pattern Richard Gesick.
Behavioral Design Pattern
DESIGN PATTERNS : State Pattern
Structural Patterns: Adapter and Bridge
Strategy Design Pattern
Informatics 122 Software Design II
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Design Lecture : 28.
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Presentation transcript:

Applying the Principles Two Examples

Example 1

© Henrik Bærbak Christensen New Requirement It would be nice with a simple GUI “to see something” instead of just xUnit tests... “The GUI History of FRS”  © Henrik Bærbak Christensen

© Henrik Bærbak Christensen [Demo] Run it Ant gui Review GUI code © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Analysis Seq Diagram No difference in behaviour of a GUI versus real hardware! © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Conclusion Any kind of user interface can operate the PayStation! Wow – Change by addition... How come we are so lucky? © Henrik Bærbak Christensen

Design considerations (3) Behaviour that may vary the same hardware must operate varying pay station implementations: AlphaTown, BetaTown, EpsilonTown... (1) Variable behaviour behind interface PayStation interface... (2) Compose behaviour by delegation Gui/Hardware does not itself calculate rates, issue receipts, etc., but lets an instance of PayStation do the dirty job... © Henrik Bærbak Christensen

Result The side effect of this decision is that interface decouples both ways!!! Hardware may operate different kinds of PayStation implementations Alpha, Beta, Gamma, … Different kinds of user interfaces may operate the same PayStation implementation Demo: dSoftArk E09 / many-to-many <<interface>> PayStation * <<interface>> PayStationGUI * © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Automagical pattern? PayStation is an example of the Facade pattern C © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Consequences Benefits Shields clients from subsystem objects (depends… Consider HotCiv) Weak coupling Many to many relation between client and façade Liabilities Bloated interface with lots of methods Because façade must have the sum of responsibilities of the subsystem How to avoid access to the inner objects? Read-only interfaces; no access (require dumb data objects to be passed and parsed over the facade). © Henrik Bærbak Christensen

Example 2

© Henrik Bærbak Christensen New Requirement Alphatown wants to log all coin entries: [time] [value] Example: 14:05:12 5 cent 14:05:14 25 cent 14:55:10 25 cent  © Henrik Bærbak Christensen

© Henrik Bærbak Christensen The 3-1-2 machinery Let us look at the machinery:  Identify the responsibility whose concrete behaviour may vary  Express responsibility as an interface  Let someone else do the job How does this apply? What is 3-1-2 here? © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Analysis  Identify the responsibility whose concrete behaviour may vary It is the “Accept payment” responsibility  Express responsibility as an interface A) PaymentAccepter role? B) PayStation role? Already in place!  Let someone else do the job Maybe let someone handle the coins before the parking machine receives them? © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Metaphor: Principle 2 © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Dynamics © Henrik Bærbak Christensen

© Henrik Bærbak Christensen [Demo] Refactoring process – solution first programming Establish basis: run TestPayStation ps = new LogDecoratedPS( ps ); In LogDecoratePS do Remove all methods Intro ‘private PayStation delegate;’ Select it, and choose ‘source/create delegate methods’ Rerun tests Introduce the decorating statement in the LogDec… © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Structure © Henrik Bærbak Christensen

Chaining decorators Decorators can form chains. New requirement: no payment possible in 19.00 – 07.00 interval :PayStationCoinLoggingDecorator :PayStationFreeParkingInterval :PayStationImpl © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Automagical pattern? The decorator is yet another application of 3-1-2 and the principles of flexible design! © Henrik Bærbak Christensen

© Henrik Bærbak Christensen Consequences Benefits Adding and removing behavior at run-time Incrementally add responsibilities Complex behavior by chaining decorators Liabilities Analyzability suffers as you end up with lots of little objects Behavior is constructed at run-time instead of being written in the static code Delegation code tedious to write (without IDE ) Make a ‘null decorator’ as base class © Henrik Bærbak Christensen