Week 2 Design Examples and Designing for Change Alex Baker
Implementation Design An implementation design is a road map – understandable, unambiguous, consistent, helpful, … An implementation design describes a path from system design to the outcome – correct, complete, concise, verifiable, effective, … An implementation design describes what the implementers should do – elegant, partitionable, recomposable, resilient, … An implementation design is a guide towards future change – evolvable, …
Emphasis on Changability Change abounds… – During design – During coding – Upon delivery – After use Reuse for later projects
Emphasis: Changability Subtle Requires foresight and careful balancing An implementation design describes what the implementers should do – elegant, partitionable, recomposable, resilient, … An implementation design is a guide towards future change – evolvable, …
Changability: Basic Principles Low Coupling: Reducing interdependency – Changes don’t propagate – Reuse is facilitated High Cohesion: Grouping functionality – Easier to find things – Metaphor guides decisions Information Hiding
The Ideal Program … vs.
A Very Simple Example A sorted list class with: 1) getArray() : Array 2) getElementAt(int i) : Element
A Very Simple Example A List class with: 1) getArray() : Array 2) getElementAt(int i) : Element Its too slow, so we switch to a hash table 1) Everywhere you call getArray needs changing 2) Only List is changed Little things like this add up
UML Review: Class Diagrams Class Name Attribute : Type Operation (parameter) : Return Type Attribute : Type Operation (parameter) : Return Type
UML Review: Class Diagrams Association Aggregation Generalization Composition
A Class Diagram
Example 1: Theseus and the Minotaur
Original Theseus Design
What if we want to add “Water” ?
Original Theseus Design What if we want to add “Water” ? ?
Original Theseus Design What if we want to add “Water” ? How do we fix this? ?
TntM: Changes Changing the board size Adding terrain types Adding more monsters Adding a second player “Intelligent elements”
TntM 2
TntM 2: Object Interfaces & Inheritance
TntM: Changes Changing the board size Adding terrain types Adding more monsters Adding a second player “Intelligent elements”
How far is too far? Changing board size? Pushable blocks? Intelligent elements? Real time gameplay? Physics challenges?
Bonus! StompOn( stompee ) Or StompedOn( stomper )
Example #2 Klax Blocks fall from above, use a paddle to catch Deposit blocks in one of 5 columns Try to make lines of 3 in a row or more klax_eng.php
A Good Klax Design?
Chiron 2 Architectural Style
C2 Klax
Spelling Klax?
Scrabble? How did you design for change?
Scrabble? How did you design for change? Could you redesign / refactor for – Changes to letter values?
Scrabble? How did you design for change? Could you redesign / refactor for – Changes to letter values? – Changes to bonus squares?
Scrabble? How did you design for change? Could you redesign / refactor for – Changes to letter values? – Changes to bonus squares? – AI opponents?
Scrabble? How did you design for change? Could you redesign / refactor for – Changes to letter values? – Changes to bonus squares? – AI opponents? – Different dictionaries?
Summary Designing for change is a matter of: – Controlling dependency – Proper encapsulation – Generalizing where you can More broadly, you are asking: – What are the biggest change risks? – What kind of program is this, essentially? – Where is “the line”?
Assignment #1 Continued We’ll exchange designs now Review forms will be online tonight Send completed forms to Andre and I – – – Due 6:00 pm, Sunday