OOP
Lecture slide: click here
Objects, classes, data and function members, constructors/destructors. OOP in C++ and Java, objects vs closures, classes vs datatypes, OO pitfalls. Readings: Scott ch 3.3.4-3.3.5, 3.7, Stroustrup ch. 8-9 (optional), Arnold ch. 13 (optional).
Styles of OOLs (object oriented languages)
Class-based
In a class-based OOP language, each object is an instance of a class.
Prototype-based
In a prototype-based OOP language, each object is a clone of another object, possibly, with modifications and/or additions.
Example:
Classes in C++
Example:
Extending a class
Example:
Dynamic despatching by vtable
vtable is used to determine which class' method to invoke.
virtual
method means: "use the subclass version" (including all descendant subclasses). Virtual methods are placed in the vtable.
Point
class vtable example:ColoredPoint
:
OOP pitfalls
Last updated