< previous page page_313 next page >

Page 313
What Have You Learned, Dorothy?
If I ever go looking for my heart's desire again, I won't look any further than my own backyard. While it is true there is no place like home, it is also true that this is nothing like procedural programming. In procedural programming, a controlling method would examine data and invoke functions.
In this, object-oriented approach, each individual object is given a narrow and well-defined set of responsibilities. The linked list is responsible for maintaining the head node. The headnode immediately passes the new data on to whatever it points to, without regard for what that might be.
The tailnode creates a new node and inserts it whenever it is handed data. It knows only one thing: if this came to me, it gets inserted right before me.
Internal nodes are marginally more complicated; they ask their existing object to compare itself with the new object. Depending on the result, either they then insert or they just pass it along.
Note that the InternalNode has no idea how to do the comparison; that is properly left to the object itself. All the InternalNode knows is to ask the objects to compare themselves and to expect one of three possible answers. Given one answer, it inserts; otherwise it just passes it along, not knowing or caring where it will end up.
So who's in charge? In a well-designed object-oriented program, no one is in charge. Each object does its own little job, and the net effect is a well-running machine.
Summary
In this hour you learned about linked lists.
A linked list is a dynamically sized collection. Each data object is held in a node in the list. To get to a particular node, you must start at one end of the list and walk the list to the node you need.
You saw how to encapsulate limited functionality into each small class in the list and how these well-designed objects can work together synergistically.

 
< previous page page_313 next page >

If you like this book, buy it!