Design Rules 101 - PowerPoint PPT Presentation

About This Presentation
Title:

Design Rules 101

Description:

Design for simplicity. Don't Use Inheritance just because you can ... Don't store two values when one can be computed from the other [unless ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 4
Provided by: georgeh1
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Design Rules 101


1
OneOne Association
Design Rules 101
v0.Source
v0.Target
  • Design for simplicity
  • Dont Use Inheritance just because you can
  • Know which classes know which other classes
  • Focus on the Responsibilities
  • Limit tanglement as much as you can
  • Dont store two values when one can be computed
    from the other unless computation is exorbitant

target
Use when Source needs a referenceto Target to
support its operations.
OneOne Bidirectional AssociationEXTRA
v1.Parent
v1.Child
child
parent
Use when Parent needs a referenceto Child, which
also needs to maintaina reference to the exact
same Parent.
Circle
OneMany Association
radius center
v2.Molecule
v2.Compound
1

void add (Compound c)void remove (Compound
c)int size()
void push(Object)
compounds
Use when Molecule needs a referenceto any number
of Compound objects, but theseCompound objects
are unaware of the Molecule
ManyMany AssociationEXTRA


Use when Source object can have associationsto
any number of Target objects, each of whom can
be associated with any number of Source objects
2
  • Observe parameters to methods
  • Perhaps method in wrong class?
  • Know when to merge a class
  • partial abstraction

1
  • Know when to split a class
  • Doing too much

TicTacToe
Create Grid class
boolean isEmpty (r, c)boolean isGridFull()void
forfeitGame()char getCurrentPlayer()boolean
hasWon()
Leave here
char board
AmidaBoard
AmidaBoard
1
1


Use ArrayList
numLines()addLine()removeLine()removeAll() addE
dge(int, int)numEdges(int)getEdge(int,
int)removeEdge(Edge e)tooClose(int,
int) exitLine(int)
lines
Delegate toLine
linesedges
3
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com