18.13 Recap

 < Free Open Study > 



18.13 Recap

The first section of this chapter listed several characteristic features of the object-oriented programming style. Let us recall these features and briefly discuss how they relate to the examples developed in the chapter.

  1. Multiple representations. All of the objects that we have seen in this chapter are counters-i.e., they belong to the type Counter. But their representations vary widely, from single reference cells in §18.2 to records containing several references in §18.9. Each object is a record of functions, providing implementations of the Counter methods (and perhaps others) appropriate to its own internal representation.

  2. Encapsulation. The fact that the instance variables of an object are accessible only from its methods follows directly from the way we build objects, building the methods by passing the record of instance variables to a constructor function. It is obvious that the instance variables can be named only from inside the methods.

  3. Subtyping. In this setting, subtyping between object types is just ordinary subtyping between types of records of functions.

  4. Inheritance. We modeled inheritance by copying implementations of methods from an existing superclass to a newly defined subclass. There were a few interesting technicalities here: strictly speaking, both the superclass and the new subclass are functions from instance variables to records of methods. The subclass waits for its instance variables, then instantiates the superclass with the instance variables it is given, forming a record of superclass methods operating on the same variables.

  5. Open recursion. The open recursion provided by self (or this) in real-world object-oriented languages is modeled here by abstracting classes not only on instance variables but also on a self parameter, which can be used in methods to refer to other methods of the same object. This parameter is resolved at object-creation time by using fix to "tie the knot."

18.13.1 Exercise [⋆⋆⋆]

Another feature of objects that is useful for some purposes is a notion of object identity-an operation sameObject that yields true if its two arguments evaluate to the very same object, and false if they evaluate to objects that were created at different times (by different calls to new functions). How might the model of objects in this chapter be extended to support object identity?



 < Free Open Study > 



Types and Programming Languages
Types and Programming Languages
ISBN: 0262162091
EAN: 2147483647
Year: 2002
Pages: 262

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net