What is an Object? A Quick Review
- Object-oriented design means modelling a problem domain with related objects.
- Objects have state and are eligible to participate in behaviors which can change that state.
- Object-oriented programming means implementing an object-oriented design with data structures and functions.
- Data structures represent the state of an object.
- Functions associated with an object define the methods for accessing and changing the state of an object, that is, for making the object behave.
- Simple objects are common in C libraries. For example, the Standard I/O library provides simple file objects consisting of a FILE data structure and a set of associated functions that operate on a pointer to a FILE structure.
- Inheritance is the relation of derivation among different types, or classes, of objects. If class Z is derived from class Y, and class Y is derived from class X, then X and Y are called base classes of Z.
- Derivation of a class from a base class means extending the base class by adding new object data, adding new object methods, and redefining existing object methods.
- Polymorphism, "having many forms," means that an object of a derived class can be referenced wherever an object of a base class is called for, but will behave as appropriate to its type. That is, if an object method has been redefined, then the redefining function, not the original function, will be called.
- Dynamic binding is a means of achieving polymorphism. With dynamic binding, when a method is invoked the function to call is determined at runtime. Dynamic binding is supported in C++ by virtual functions. C provides no equivalent facility, but switch statements or pointers to functions can be used to imitate it. Static binding is monomorphic. When a method is invoked, the function to call is determined at compile time. Static binding is supported by ordinary C function calls.