Frogs design

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
Line 18: Line 18:
 
== Broken heuristics ==
 
== Broken heuristics ==
  
* [[Beware type switches]]
+
* [[Beware type switches]] - ''Frog'' phases: ''Egg'', ''Tadpole'', ''AdultFrog''.
* [[Beware value switches]]
+
* [[Beware value switches]] - ''Tadpole''
* [[Avoid no-op overrides]]
+
* [[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]]
+
* [[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.
  
 
:''This is a good start, but needs some explanation of how the rules are broken here.  Also needs a note about this conribution on the talk page. --[[User:Warwick Irwin|Wal]] 22:44, 22 July 2008 (UTC)''
 
:''This is a good start, but needs some explanation of how the rules are broken here.  Also needs a note about this conribution on the talk page. --[[User:Warwick Irwin|Wal]] 22:44, 22 July 2008 (UTC)''

Revision as of 22:58, 22 July 2008

An OO model of frogs. This beautiful design appeared in the 2004 427 exam.

Frogs.gif

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.

Design Critique

This design is perfect. It cannot be faulted.

Broken heuristics

  • Beware type switches - Frog phases: Egg, Tadpole, AdultFrog.
  • Beware value switches - Tadpole
  • 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.
This is a good start, but needs some explanation of how the rules are broken here. Also needs a note about this conribution on the talk page. --Wal 22:44, 22 July 2008 (UTC)
Personal tools