Becomes problem

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(new page with link to avoid becomes heuristic and frogs)
 
 
(One intermediate revision by one user not shown)
Line 2: Line 2:
 
You want an object to change its behavior but stay the 'same' object.   
 
You want an object to change its behavior but stay the 'same' object.   
  
An example of this is given in the [[Frogs design]]:  have a frog object that must somehow change from egg to tadpole to frog (and ultimately to dead frog), wiht different ways of moving, but stay a frog.  The problem is that inheritance is not dynamic.  This is one example of the weakness of '[[Model the real world|model the real world]]' as a design maxim:  in the real world we easily accept that the tadpole is the "same" as the adult frog but our notions of type in the real world are much richer and more complex than interface and behaviour.  The "becomes" problem is often indicated by type switches (see [[Beware type switches]]).  See Riel's heuristic "[[Avoid becomes|Do not model the dynamic semantics of a class with inheritance]]".
+
An example of this is given in the [[Frogs design]]:  we have a frog object that must somehow change from egg to tadpole to frog (and ultimately to dead frog), with different ways of moving, but stay a frog.  The problem is that inheritance is not dynamic.  This is one example of the weakness of '[[Model the real world|model the real world]]' as a design maxim:  in the real world we easily accept that the tadpole is the "same" as the adult frog but our notions of type in the real world are much richer and more complex than interface and behaviour.  The "becomes" problem is often indicated by type switches (see [[Beware type switches]]).  See Riel's heuristic "[[Avoid becomes|Do not model the dynamic semantics of a class with inheritance]]".

Latest revision as of 05:07, 19 October 2010

The "becomes" problem

You want an object to change its behavior but stay the 'same' object.

An example of this is given in the Frogs design: we have a frog object that must somehow change from egg to tadpole to frog (and ultimately to dead frog), with different ways of moving, but stay a frog. The problem is that inheritance is not dynamic. This is one example of the weakness of 'model the real world' as a design maxim: in the real world we easily accept that the tadpole is the "same" as the adult frog but our notions of type in the real world are much richer and more complex than interface and behaviour. The "becomes" problem is often indicated by type switches (see Beware type switches). See Riel's heuristic "Do not model the dynamic semantics of a class with inheritance".

Personal tools