Intent:
Introduce message passing and encapsulation and provide a
demonstration of how the OO approach is inherently more robust
than the procedural.
Method:
Pick two students.
Pick the most outgoing and try to lift him/her out of their seat
without telling them what you are doing.
On a piece of paper write "Please stand up" and hand this to the
other student.
Get them seated again and explain the demonstration
If It Works:
1) Students should appreciate that when sent an appropriate
message behaviour is induced robustly.
2) Students should also appreciate that external functions
acting on a data structure (trying to rearrange the state of the
students musculo-skeletal system) is prone to error unless the
exact algorithm is applied to identical objects.
3) If the piece of paper is passed around the room, the state of
the entire collection of objects is changed purely due to message
passing with encapsulated behaviour. One person may stand up
differently to the next and so on.. but the desired result is
achieved without undue problem.
Issues to consider:
Be careful in choice of analogy and 'victim' in order to avoid causing offence (to
physically challenged students for example).
Try not to pick the largest and heaviest student in the room to
manipulate. Whilst highly amusing to the students and still
possible to explain why the algorithm doesn't work, you run the
risk of missing the point (and hurting yourself !)
Alternative:
If manipulating students is unacceptable try having them write
name badges. Pass a message to one student to write their name
on the board showing encapsulated behaviour. Take the name
badge of another student, copy the name onto the board and throw the badge into the
nearest bin (return value not specified by algorithm). This
works almost as well.
| Previous pattern | Search This Site | Next pattern |