Frogs design
From CSSEMediaWiki
(Difference between revisions)
Line 11: | Line 11: | ||
* ''Toad''s don’t have the same lifecycle as ''Frog''s, but they look and act a lot like ''Frog''s. | * ''Toad''s don’t have the same lifecycle as ''Frog''s, but they look and act a lot like ''Frog''s. | ||
* ''Toad''s eat ''AdultFrogs''. | * ''Toad''s eat ''AdultFrogs''. | ||
− | |||
− | |||
− | |||
− | |||
== Broken heuristics == | == Broken heuristics == | ||
− | * [[ | + | * [[Avoid becomes]] - ''Frog'' phases of life are modeled by inheritance: ''Egg'' ''Tadpole'', ''AdultFrog''. |
− | * [[ | + | * [[Beware type switches]] - the ''phase'' variable in ''Frog'' is based on the type of an object (''Frog''). |
− | * [[Beware value switches]] - ''Tadpole'' | + | * [[Beware value switches]] - the ''swim()'' method in ''Tadpole'' differs in behavior based on the value of an attribute (''type''). |
* [[Avoid no-op overrides]] ("Design by Contract") - the derived class ''Egg'' overrides the base class's ''hop()'' and ''swim()'' methods with methods which does nothing. | * [[Avoid no-op overrides]] ("Design by Contract") - the derived class ''Egg'' overrides the base class's ''hop()'' and ''swim()'' methods with methods which does nothing. | ||
* [[One key abstraction]] - the ''Move'' interface contains more than one key abstraction. It contains methods to move such as ''hop()'' and ''swim()'', but it also contains a ''display()'' method which is a separate key abstraction. | * [[One key abstraction]] - the ''Move'' interface contains more than one key abstraction. It contains methods to move such as ''hop()'' and ''swim()'', but it also contains a ''display()'' method which is a separate key abstraction. | ||
− | |||
− | |||
== "Feels Bad" == | == "Feels Bad" == | ||
* ''Toad'' is a subclass of ''AdultFrog''. | * ''Toad'' is a subclass of ''AdultFrog''. | ||
− | * ''FrogBrain'' contains an array of ''Egg'' | + | * ''FrogBrain'' contains an array of ''Egg''. |
:''Why do these things feel bad? --[[User:Warwick Irwin|Wal]]'' | :''Why do these things feel bad? --[[User:Warwick Irwin|Wal]]'' |
Revision as of 05:33, 23 July 2008
An OO model of frogs. This beautiful design appeared in the 2004 427 exam.
Contents |
Design notes
- This design models the lifecycles of Frogs.
- A Frog begins life as an Egg, grows into a Tadpole and then an AdultFrog.
- A FrogBrain belongs to a Frog and manages its behaviour.
- There is one Biologist, Igor, who sometimes moves Frogs around. Igor has been known to fry their legs in white wine.
- Toads don’t have the same lifecycle as Frogs, but they look and act a lot like Frogs.
- Toads eat AdultFrogs.
Broken heuristics
- Avoid becomes - Frog phases of life are modeled by inheritance: Egg Tadpole, AdultFrog.
- Beware type switches - the phase variable in Frog is based on the type of an object (Frog).
- Beware value switches - the swim() method in Tadpole differs in behavior based on the value of an attribute (type).
- Avoid no-op overrides ("Design by Contract") - the derived class Egg overrides the base class's hop() and swim() methods with methods which does nothing.
- One key abstraction - the Move interface contains more than one key abstraction. It contains methods to move such as hop() and swim(), but it also contains a display() method which is a separate key abstraction.
"Feels Bad"
- Toad is a subclass of AdultFrog.
- FrogBrain contains an array of Egg.
- Why do these things feel bad? --Wal
Go export yourself
Should a Frog be able to export itself?