Mandatory 3 Test Stubs State Abstract Factory. Do not panic! dSoftArk is about Good analyzable design not about HotCiv! Henrik Bærbak Christensen2.

Slides:



Advertisements
Similar presentations
DAIMIHenrik Bærbak Christensen1 Testability Tactics How to make software testable...
Advertisements

Observer Method 1. References Gamma Erich, Helm Richard, “Design Patterns: Elements of Reusable Object- Oriented Software” 2.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Stéphane Ducasse«ChapterNr».1 Arthur Riel Design Heuristics from Object-Oriented Design Heuristics by Arthur Riel Read the Heuristics… –Find reasons why.
Inheritance (notes for 10/26 lecture). Inheritance Inheritance is the last of the relationships we will study this semester. Inheritance is (syntactically)
DAIMI(c) Henrik Bærbak Christensen1 JUnit A tool for test case management.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Inheritance and Polymorphism CS351 – Programming Paradigms.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
Introduction To System Analysis and design
COP 3003 Object-Oriented Programming - Polymorphism Dr. Janusz Zalewski, Fall 2013 Prepared by Dr Dahai Guo.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Design Patterns.
OOPs Object oriented programming. Based on ADT principles  Representation of type and operations in a single unit  Available for other units to create.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns 1.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
Inheritance - Polymorphism ITI 1121 Nour El Kadri.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Patterns in programming1. 2 What are patterns? Answers to common design problems. A language used by developers –To discuss answers to design problems.
Design Patterns. OO-Concepts Don’t rewrite code Encapsulation Inheritance Write flexible code.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
The HotCiv GUI Instantiating the MiniDraw Framework.
Inheritance Revisited Other Issues. Multiple Inheritance Also called combination--not permitted in Java, but is used in C++ Also called combination--not.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
OOPs Object oriented programming. Abstract data types  Representationof type and operations in a single unit  Available for other units to create variables.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
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.
Hints - Mandatory 2 / Strategies. Learning... life-a-curve.html B Christensen2 Jeg fatter ikke.
Multi Dimensional Variance: How to make ultra flexible software!
Mandatory 1 / AlphaCiv … Traps to be aware of …. Warn or not? I once asked Kent Beck the following –I have a lot of students in a course in design patterns.
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...
MiniDraw Introducing a Framework... and a few patterns.
Mandatory 2 / Strategies Note: I publish this presentation at the week plan for week 4.
Mandatory 1 / AlphaCiv … a few comments…. Overall: Generally – good work – good effort Seems you are generally doing TDD Minor hick-ups –”My own way is.
Patterns are Roles What patterns are and what not…
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
CH10 Supplementary Material Prepared by Fatimah Alakeel Oct 2010.
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Class Relationships Lecture Oo08 Polymorphism. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 10 p.125 n Fowler & Scott, UML.
Mandatory 3 Test Stubs State Abstract Factory. Stubs, Spies, and Fake Objects One Example Making distribution testable... Henrik Bærbak Christensen2.
Class Diagrams Revisited. Parameterized Classes Parameterized Classes - are used to represent relationships between templates.
Observations Week 4. Observe Code Change! Review week plan! Also, a load generator is added to the exercises on Iteration 3 for ‘smoking out’ the exceptions.
Strategy in 15 minutes... derived from the principles.
CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
3/1/01H-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Evaluating Class Diagrams Topics include: Cohesion, Coupling Law of Demeter (handout)
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Hints - Mandatory 5 Blackbox Testing Pattern Hunting.
Instantiating the MiniDraw Framework
Introducing a Framework ... and a few patterns
Low Budget Productions, LLC
Exam A few notes and hints….
HotCiv Project Starting up!.
Mandatory 1 / AlphaCiv … Traps to be aware of ….
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Presentation transcript:

Mandatory 3 Test Stubs State Abstract Factory

Do not panic! dSoftArk is about Good analyzable design not about HotCiv! Henrik Bærbak Christensen2

Ecosense Karibu framework Henrik Bærbak Christensen3 RabbitMQ Mirrored Cluster MongoDB ReplicaSet / 3 Instances

Stubs – allow us to test! Henrik Bærbak Christensen4

Happy path test Henrik Bærbak Christensen5 Send the objects Validate they are stored in the DB

... on test doubles... Henrik Bærbak Christensen6

... And simulate failure situations Henrik Bærbak Christensen7

Back to HotCiv EpsilonCiv needs a die roll –Randomness makes auto testing inefficient –Stub the die! –Make a ‘PredictableDieStrategy’ with a void setSequence(int[] dieValuesToRoll); –... And of course a RealDieStrategy = random die And – inject the proper strategy for testing Henrik Bærbak Christensen8

Which one is the Test Stub? Henrik Bærbak Christensen9

This is not Abstract Factory! Henrik Bærbak Christensen10

This is not Abstract Factory! Henrik Bærbak Christensen11 Question: How to reconfigure at run-time?

AbsFactory – UML clutter... Henrik Bærbak Christensen12

Abstract Factory Hierarchy Question: –Interface: CivFactory –Subclass: AlphaFactory implements CivFactory –??: BetaFactory extends AlphaFactory Fine – Beta IS-A Alpha with some changes, so the subclass hierarchy works out OK – but naming bad! > Figure – > AbstractFigure –RectangleFigure, CircleFigure, LineFigure,... Extend AbstractFigure Henrik Bærbak Christensen13

Abstraction and parameterization When we introduce Green and Yellow player? Henrik Bærbak Christensen14

Design is About Being Consistent! If you decide to use Observer for you WinnerStrategy to solve ZetaCiv... Then you refactor this decision into existence consistently – or die the ‘if hell’ Henrik Bærbak Christensen15

Remember: Refactor Henrik Bærbak Christensen16

What can I do? Henrik Bærbak Christensen17

Appears General – but is not Henrik Bærbak Christensen18

Curiosities Henrik Bærbak Christensen19

State – and annoying state! Who stores what? Attacks won by player Henrik Bærbak Christensen20

Problem statement When doing compositional designs we –Cut behaviour that is often otherwise in the same abstraction, and therefore have access to the same state (i.e. The same set of instance variables)... Parametric: all in the same class Polymorphic: subclasses still contain all of superclass var. –... Into multiple objects But how do they share/exchange state!!! Henrik Bærbak Christensen21

Example WinnerStrategy: Algorithm to determine winner Based upon knowledge of –Alpha: The age (correlates to rounds) –Beta: Owner of all cities –Epsilon:Attacks won by player –Zeta:Rounds+Beta+Epsilon’ Epsilon’ = counting only starts after 20 rounds But who is responsible for ”knowing it”? Henrik Bærbak Christensen22

Example Who should know it? –Game or the WinnerStrategy or some third object? –Game/WinnerS: Number of rounds played/age –Game: Owner of all cities –WinnerS:Attacks won by player –WinnerS:Counting only starts after 20 rounds Known by Game Not really known by the Game Henrik Bærbak Christensen23

Solution 1 Let the GameImp store all this state + provide accessor methods for them Fine for –Game/WinnerS: Number of rounds played –Game: Owner of all cities –See Finn’s note on the weekplan But should game count attacks? –Augment the Game interface? Or GameImpl? See Finn’s discussion of ’Private Interfaces’ –Change game to suit a single strategy? Henrik Bærbak Christensen24

Solution 2 Augment the WinnerStrategy interface, to capture state –incrementRoundCount(); –incrementAttacksWon(Player p); –cityOwnerChanged(Position p); –All info local to the winner algorithm (cohesion) –No irrelevant data captured in Game (cohesion) –No accessor methods introduced in Game only for the strategy  –GameImpl has to invoke these methods (and only once!) (low cohesion) –Many strategies do not need that info anyway Well-known property of Strategy –Not open to further weird strategies Henrik Bærbak Christensen25

Solution 3 (bit similar to 2) Rather complex solution but with merits... –Create a GameEventObserver, let GameImpl call its methods: cityCreated(Position p) attackPerformed(Unit winner); roundIncrement(); Let our strategy register as observer of the game –Can do its own counting = no irrelevant state in Game –But GameImpl has to call ‘notifyAttackWonBy(p)’  –Can be used for other purposes, like scoring graphs –Can probably suit new strategiest that count other stuff... Henrik Bærbak Christensen26

Scores... Basically we either –1) Add strategy specific state into Game That is not used by most variants  State has to be properly maintained (remember to incr. Battel counter) –2) Add strategy specific method calls into Game That lowers readability of game  That obey a sensitive protocol  –i.e. ’global analysis’ of GameImpl to ensure that ’incrementBattleCount()’ is called once and only once (Observer solution is basically a variant of this theme) Which is the lesser evil? Henrik Bærbak Christensen27

But make it general! This is a ’responsibility eroding’ way of doing it This is basically a parametric solution! If ( variant == ZetaCiv ) { [increment counter] } Thus you get the worst of both world  Henrik Bærbak Christensen28 In game.moveUnit: if(winnerstrategy instanceof BattleWinner) { ((BattleWinner) winnerstrategy).winBattle(unit.getOwner(), this); }

Others Solution 1) / battle counter in Game + A ’resetBattleCount()’ in GameImpl –Invoked by the strategy after the 20th round Bad idea! –State in game => other parts may start using this information –But in one variant the count mysteriously resets after 20 rounds??? Henrik Bærbak Christensen29

36.18: Alpha map = a test stub? A wonderful discussion with TAs –”AlphaCiv map defined by particular customer, thus it is not a test stub” It is in a production code folder This is of course right, but... –World layout optimized to support testing Supports ’evident test’ (units close for testing terrain) Is static (no randomness) –Thus feeds indirect input, defined by test code Henrik Bærbak Christensen30

(so what is the answer?) The answer (as often in this course) is Sound and clear Argumention On one hand Alpha Map exhibits –(arguments in favour of considering it a test stub) On the other hand –(arguments in favour of considering it a test stub) Therefore we conclude – Henrik Bærbak Christensen31