Mandatory 1 / AlphaCiv … Traps to be aware of ….

Slides:



Advertisements
Similar presentations
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Advertisements

Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Unit 031 Interfaces What is an Interface? Interface Declaration Syntax Implementing Interfaces Using Interfaces as Types Interfaces and Inheritance Interfaces.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Test-Driven Development “Test first, develop later!” –OCUnit.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
CSC 213 – Large Scale Programming. Why Do We Test?
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
SAMANVITHA RAMAYANAM 18 TH FEBRUARY 2010 CPE 691 LAYERED APPLICATION.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Chapter 21 Test-Driven Development 1CS6359 Fall 2011 John Cole.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
OO Methodology Elaboration Iteration 2 - Design Patterns -
Test-Driven Development Eduard Miric ă. The problem.
The HotCiv GUI Instantiating the MiniDraw Framework.
Refactoring - 1 CS494: Intro. to Refactoring Readings: –Refactoring for everyone: How and why to use Eclipse's automated refactoring features. By David.
Test Stubs... getting the world under control. TDD of State Pattern To implement GammaTown requirements I CS, AUHenrik Bærbak Christensen2.
CS 350 – Software Design Expanding Our Horizons – Chapter 8 The traditional view of objects is that they are data with methods. Sometimes objects could.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 6: Using Design Patterns.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
More Design Patterns From: Shalloway & Trott, Design Patterns Explained, 2 nd ed.
HotCiv Project Starting up!. Henrik Bærbak Christensen2 HotCiv = Agile development Iterations of –product development –learning increments.
Session 7 Introduction to Inheritance. Accumulator Example a simple calculator app classes needed: –AdderApp - contains main –AddingFrame - GUI –CloseableFrame.
Hints - Mandatory 2 / Strategies. Learning... life-a-curve.html B Christensen2 Jeg fatter ikke.
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...
Refactoring and Integration Testing or Strategy, introduced reliably by TDD The power of automated tests.
AU CSHenrik Bærbak Christensen1 dSoftArk Software Architecture Programming in the Large.
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.
CS, AUHenrik Bærbak Christensen1 Compositional Design Principles The “GoF” principles Or Principles of Flexible Design.
Mandatory 3 Test Stubs State Abstract Factory. Do not panic! dSoftArk is about Good analyzable design not about HotCiv! Henrik Bærbak Christensen2.
Strategy in 15 minutes... derived from the principles.
AU CSHenrik Bærbak Christensen1 dSoftArk E2013 Software Architecture Programming in the Large.
Instantiating the MiniDraw Framework
Introducing a Framework ... and a few patterns
Unit Testing - solid fundamentals
Module Road Map Refactoring Why Refactoring? Examples
Phil Tayco Slide version 1.0 Created Sep 18, 2017
GoF Patterns (GoF) popo.
Applying the Principles
What to do when a test fails
CS 350 – Software Design The Strategy Pattern – Chapter 9
Exam A few notes and hints….
HotCiv Project Starting up!.
Compositional Design Principles
COTS testing Tor Stålhane.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Encapsulation & Visibility Modifiers
Overview of Eclipse Lectures
Object-Oriented Programming Using C++ Second Edition
SE-2811 Software Component Design
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
State Pattern By the Group of Four.
Review of Previous Lesson
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Software Development Techniques
HFOOAD Chapter 5 Interlude
Software Engineering and Architecture
Refactoring.
Software Engineering and Architecture
Software Engineering and Architecture
Software Engineering and Architecture
Presentation transcript:

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. How can I best teach them the benefits? A) Give them a problem to solve, make them solve it, and then show a brilliantly simple solution using pattern X? B) Give them a problem and ask them to solve it using pattern X? Kent’s answer was: (To be given at lecture )

Doing TDD Evident Tests Exercise: What is focus here? Test that everything works? Or Drive production code into existence?

What is TDD??? Traditional tests = Quality Assurance Technique Success: test cases that show absence of defects TDD tests = Implementation Technique Success: test cases that drive implementation Perhaps a few more to show absense of defects Not a comprehensive quality assurance technique

How I will do it… Iteration 1: Fake it using anonymous tile class Iteration 2: Intro datastructure, intro StandardTile, fill all with plains Productioncode driver Reliability

And then I… Add test cases for each of the ‘exceptions’ Test drive that one tile that is a mountain Write the test case ‘shouldHaveMountainAt2_2()’ See it fail Enhance the production code to world[2][2] = new StandardTile(GameConstants.MOUNTAIN); (or world.put(new Position(2,2), new StandardTile…..) (or …) See it pass Test drive that one that is Ocean You get it…

… and one more hint Have a look at my screencast on weekplan 2 ‘unit-move-faked’

Evident tests again Why do you not think all CityImpl are the same? Just test the production code on one instance! Exercise: Is it OK to use CityImpl here (as in ‘use City interface instead’) Answer: Yes indeed. Why? Because we are TDD’ing the implementation of City, and the getTreasury() may just be a method on the IMPL class. Do unit testing of City, Unit, etc; and less testing through the Game. Unit Testing

Production and Test Code Separate test and production code as best possible! Morale: No test code in the production code Unless you cannot avoid it… Testability is more important than encapsulation… As long as you do not make mutators… Seen in GameImpl: One of the big issues in dSoftArk – it is about design and no absolute truths nor QEDs.

Misunderstood subclassing Class MountainTile implements Tile ? Why is the ratio liabilities/benefits so askewed that it is wrong to introduce MountainTile? Sorry, these are older slides. The getPosition() method was removed from the Tile interface in 2014.

When to use subclassing! Only use subclasses if you get a distinct behavioural advantage Otherwise it is a lot of typing just to define some constant Similar for units: cost, defense, attack,.... Parameterization is run-time changeable, cheap, easy to overview... One issue: Too many academic textbooks overuse subclassing. They are plainly wrong!

Regarding Units Unit types are behavioural distinct! So: SettlerUnit extends AbstractUnit impl. Unit ? Polymorphic design and it will work With some not-so-nice hacks ala How does a settler unit kill itself as part of its action? But the learning goal in dSoftArk is compositional design  Make a UnitImpl, and delegate actions to a Strategy! In the next mandatory exercises, for now just ‘simplicity’ See if you can get through... Tricky with Archers though 

Easter Eggs ?

... And this What does this code do? War stories Microsoft and easter eggs... DSE and dead code springing to life...

Read-Only Interfaces Warning: The next couple of slides are a bit complex… The central statements are: Only the Game instance is allowed to modify internal game state… How do we ensure that there are no other mutator methods visible to, say, the GUI programmers than those in Game interface? Return to these slides when need arise…

Keeping the facade Since I wrote the book I have become more strict in my understanding of mutation... Exercise: How is a city created? What happens when it does? b) How is production set? And how many ways can we set it? And how to ensure consistency? If ‘game’ is declared as ‘Game’ this is wrong, as we open up for creating-cities-through-other-means-than-the-game-rules-that-require-a-settler. If ‘game’ is a GameImpl, then createCity can be a package protected method, and I would say it is OK; it is shielded from being misused by Bjarne in the GUI department. However City is problematic, as it now has a ‘setProductionCurrency’ method that may mutate its state outside of Game’s control

Morale: Only Game has mutator methods! Design Issues Read-only interfaces for City, Tile, Unit – Why? Otherwise two ways of changing state in a game Through Game which will enforce consistency Through City which will NOT enforce consistency If there are two ways Bjarne will use the wrong one! Morale: Only Game has mutator methods! But how to change state? Only CityImpl has mutators; GameImpl only use CityImpl? ModifiableCity interface; GameImpl only use that GameImpl takes on all responsibility?

Sketches Knowing the Implementation type in Game Liabilities Fails if we must allow external clients to configure our Game with new City implementations  Dependency injection and stuff... ()

Sketches Using an ”modifiable interface” Now the Game can get any class that implements ModifiableCity injected and handle it... ModifiableCity

My opinion It is fully OK for GameImpl to Operate through CityImpl, UnitImpl, etc. Do a cast ala (CityImpl) this.getCityAt(p) Why: Because we are developing the internal production code The GUI guys only use Game interface The Domain guys (= us) use the internals

My opinion ”More beautiful” to use a ‘ModifiableCity’ interface? Simplicity: maximize work not done We do not need it at the moment It introduces more complexity If need arise, easy to refactor CityImpl -> ModifiableCity