Week 2 Design Examples and Designing for Change

  • Slides: 55
Download presentation
Week 2 Design Examples and Designing for Change Alex Baker

Week 2 Design Examples and Designing for Change Alex Baker

Implementation Design l An implementation design is a road map – l An implementation

Implementation Design l An implementation design is a road map – l An implementation design describes a path from system design to the outcome – l correct, complete, concise, verifiable, effective, … An implementation design describes what the implementers should do – l understandable, unambiguous, consistent, helpful, … elegant, partitionable, recomposable, resilient, … An implementation design is a guide towards future change – evolvable, …

Emphasis: Changability l Subtle l Requires foresight and careful balancing l An implementation design

Emphasis: Changability l Subtle l Requires foresight and careful balancing l An implementation design describes what the implementers should do – l elegant, partitionable, recomposable, resilient, … An implementation design is a guide towards future change – evolvable, …

Emphasis: Changability l l l Reusable Extensible Maintainable Portable Well-Documented Adaptable l l l

Emphasis: Changability l l l Reusable Extensible Maintainable Portable Well-Documented Adaptable l l l l Efficiency Powerful Simplicity Readability Minimalistic Elegant Well-Organized Concise

Changability: Basic Principles l Low Coupling: Reducing interdependency – – l High Cohesion: Grouping

Changability: Basic Principles l Low Coupling: Reducing interdependency – – l High Cohesion: Grouping functionality – – l Changes don’t propagate Reuse is facilitated Easier to find things Metaphor guides decisions Information Hiding

Information Hiding Made Very Simple l A List class with: 1) 2) get. Array()

Information Hiding Made Very Simple l A List class with: 1) 2) get. Array() : Array get. Element. At(int i) : Element

Information Hiding Made Very Simple l A List class with: 1) 2) l Its

Information Hiding Made Very Simple l A List class with: 1) 2) l Its too slow, so we switch to a hash table 1) 2) l get. Array() : Array get. Element. At(int i) : Element Everywhere you call get. Array needs changing Only List is changed Little things like this add up

The Ideal Program vs. …

The Ideal Program vs. …

Why the Emphasis on Changability? l Change abounds… – – – During coding After

Why the Emphasis on Changability? l Change abounds… – – – During coding After use Reuse for later projects

Why is there so Much Change? Designs Outcomes

Why is there so Much Change? Designs Outcomes

Why is there so Much Change? Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why is there so Much Change? Software Engineering Designs Physics Principles Existing Examples Outcomes

Why the Emphasis on Changability? l Change abounds… – – – l During coding

Why the Emphasis on Changability? l Change abounds… – – – l During coding After use Reuse for later projects You usually just don’t know for sure…

Changes During Coding l Refinement of the high level design l Dependencies reveal themselves

Changes During Coding l Refinement of the high level design l Dependencies reveal themselves – – Oh, I need to know [X]. I can’t access that data? l ‘It turns out this class is HUGE’ l Need to redesign as you go Can changes be made within the design? l

Changes during Use l Potential breakdowns at several levels – Customers have needs –

Changes during Use l Potential breakdowns at several levels – Customers have needs – Customers make requests – Developers provide software

Reuse l A changing of context l …

Reuse l A changing of context l …

Change Happens l Let’s design for it

Change Happens l Let’s design for it

Our Approach l Lots of examples (3 problems, many solutions, today) l Some overarching

Our Approach l Lots of examples (3 problems, many solutions, today) l Some overarching lessons l Build up an intuition

UML Review: Class Diagrams Class Name Attribute : Type Operation (parameter) : Return Type

UML Review: Class Diagrams Class Name Attribute : Type Operation (parameter) : Return Type

UML Review: Class Diagrams Association Generalization Aggregation Composition

UML Review: Class Diagrams Association Generalization Aggregation Composition

A Class Diagram

A Class Diagram

Example #1: Theseus and the Minotaur l http: //www. logicmazes. com/theseus. html

Example #1: Theseus and the Minotaur l http: //www. logicmazes. com/theseus. html

Original Theseus Design

Original Theseus Design

Original Theseus Design l What if we want to add “Water” ?

Original Theseus Design l What if we want to add “Water” ?

Original Theseus Design l What if we want to add “Water” ? ?

Original Theseus Design l What if we want to add “Water” ? ?

Original Theseus Design l What if we want to add “Water” ? ? l

Original Theseus Design l What if we want to add “Water” ? ? l How do we fix this?

Tnt. M: Changes l Changing the board size l Adding terrain types l Adding

Tnt. M: Changes l Changing the board size l Adding terrain types l Adding more monsters l Adding a second player l “Intelligent elements”

Tnt. M 2

Tnt. M 2

Tnt. M 2: Object Interfaces & Inheritance

Tnt. M 2: Object Interfaces & Inheritance

Tnt. M: Changes l Changing the board size l Adding terrain types l Adding

Tnt. M: Changes l Changing the board size l Adding terrain types l Adding more monsters l Adding a second player l “Intelligent elements”

How far is too far? l Changing board size? l Pushable blocks? l Intelligent

How far is too far? l Changing board size? l Pushable blocks? l Intelligent elements? l Real time gameplay? l Physics challenges?

Tnt. M 2

Tnt. M 2

Bonus! l Stomp. On( stompee ) Or l Stomped. On( stomper )

Bonus! l Stomp. On( stompee ) Or l Stomped. On( stomper )

Aside: Three Degrees of Support l Is it a good solution? l Can they

Aside: Three Degrees of Support l Is it a good solution? l Can they build that solution? l Can that solution be used to make other good solutions?

Example #2 Klax l l Blocks fall from above, use a paddle to catch

Example #2 Klax l l 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 http: //www. 123 games. dk/game/puzzle/klax 3 d/ klax_eng. php

A Good Klax Design?

A Good Klax Design?

Chiron 2 Architectural Style

Chiron 2 Architectural Style

C 2 Klax

C 2 Klax

Spelling Klax?

Spelling Klax?

Spelling Klax?

Spelling Klax?

Example #3: Scrabble

Example #3: Scrabble

Function Overload Changes to rack

Function Overload Changes to rack

Class Overload

Class Overload

(besides missing details)

(besides missing details)

Is this a good design?

Is this a good design?

Overengineered? What change are you designing for? Multiple point values for a given tile

Overengineered? What change are you designing for? Multiple point values for a given tile type? More types of board objects?

Overengineered? Meanwhile: Board doesn’t actually work Populating the tiles is likely a hassle Tilepool

Overengineered? Meanwhile: Board doesn’t actually work Populating the tiles is likely a hassle Tilepool vs. Player. current. Tiles Inelegance lead to problems

A Nice Approach?

A Nice Approach?

A Nice Approach?

A Nice Approach?

Scrabble l Can a design accommodate: – Changes to letter values? – Changes to

Scrabble l Can a design accommodate: – Changes to letter values? – Changes to bonus squares? – AI opponents? – Different dictionaries?

Summary l Designing for change is a matter of: – – – l Controlling

Summary l Designing for change is a matter of: – – – l Controlling dependency Proper encapsulation Generalizing where you can Which changes? – – – What are the biggest change risks? What kind of program is this, essentially? Where is “the line”?

Practically: l What is the core we know will be true? – l What

Practically: l What is the core we know will be true? – l What variations on that will we see? If there’s something that needs to change: – – Can it be changed in one place? Does anything else need to be changed when it changes? l Can each class ignore its context? l Discipline

Assignment #1 Continued l []

Assignment #1 Continued l []