next up previous contents
Next: Java Interlude 2 Parameter Up: Interfaces: Applications Previous: Iterators   Contents

Ports and interaction with ``state''

An Iterator is a simple example of a situation where the interaction with an object is not memoryless. Normally, when an object provides access to a private variable localdata through an accessor method get_localdata(), each call to get_localdata() is independent and the value returned does not depend on how many times, if any, get_localdata() has been invoked earlier.

In contrast, the accessor method get_next() provided by the Iterator interface returns different values depending on the history of previous calls to the same method. Thus, some state information has to be maintained by the object to ensure that the value returned by get_next() is accurate.

In general, the OO paradigm does not provide any direct way of specifying such ``interactions with state'' with an object. The word port has been used recently in certain specification methodologies (e.g., UML) to refer to a point of interaction with an object that is accompanied by a state. As we have seen with Iterators, ports can be simulated indirectly by exporting objects from within a class that implement a specified interface.


next up previous contents
Next: Java Interlude 2 Parameter Up: Interfaces: Applications Previous: Iterators   Contents
Madhavan Mukund 2004-04-29