Assignment for Object Oriented Programming (OP216) Question1: Discuss the following characteristics in these areas: definition, purposes, weakness and strengths, and with an appropriate example.
Has- A relationship: 1. Definition: In the relation of class A and class B, if instances of class A contain instances of class B, this is called A has-a B, this relation usually be through a pointer, reference, or even physical containment to communicate, this also called aggregation.
2. Purposes: it is reuse of software in object oriented programming.
3. Advantage: it can compose new behavior using different objects, it is able to add new capabilities to exiting objects, so it enables the software highly flexible to suit the change of requirements.
4. Disadvantage: because of the extra level of indirection, this result to Run-time inefficiencies. And the aggregation object behavior is harder to understand and describe. When implementing reliable the object relationship also requires careful attention to resource management responsibilities.
5. Example: A Car containing an Engine, a Car object has no special privilege with its contained Engine object, An object of Car operates the Engine object only through its interface or member function.
Inheritance: 1. Definition: It implies generalization-specialization from base class to derived class. The base class is a general class whose behavior can be specialized in the derived class(es).
2. Purposes: it help use to solve some tough problems and make the solution more elegant than one without it. It is one of the fundamental tools for code reusability. It is also used as key to interface and design reuse, which is essential for building robust, extensible software.
3. Advantage: It allows designer and programmer to extend and enhance software without any recompilation cost. It is somewhat hidden, new class can be added to the hierarchy without affecting any client.