Posts

Showing posts with the label OOP

Aggregation and Composition

Image
When determining the relationship between object at design time, it is easy to succumb to the habit of using inheritance; simply because it is easy.  In a language such as C++, it is even easier to do so because the language supports multiple inheritance. Figure  1 : the java.util. List  Interface Assume that Java does not have a Stack (java.util.Stack) class and you need to create a custom stack (call it MyStack).  You could do this in three different ways, but for the purposes of this paper I will discard the creation of the Stack class as shown in the image above.  Therefore, assume that there are only two ways.  The first way is to extend the ArrayList class.  The second way is to include an ArrayList object as a data member.  The first solution uses inheritance to solve the problem.  Remember, inheritance establishes an “is-a” relationship between objects.  Therefore, the relationship between MyStack and ArrayList is incorrect since a stack is not

Specialization, Generalization, and Abstraction

Image
A question was raised on LinkedIn (you can follow me there: https://www.linkedin.com/in/hector-fontanez ) that got me thinking and I decided to blog about it. I am going to start by defining what generalization means in Object-Oriented Programming (OOP) and Design (OOD). Generalization in OOD implies that a specialized (child) class is based on a general (parent) class. This, in turn, implies a "is-a" relationship. When you analyze the object types and their relationships as depicted in the image above, from left to right, it goes from very general to more specific. You could say that an Animal "is a" more general form of Dog, of Canine, and even than Mammal. Likewise, a Canine "is a" more general form of Dog. If you analyze it from right to left, the opposite happens: it goes from more specific to more general. Put in other terms, the type gets broadened. Therefore, you can still refer to dogs as canines, mammals, or even animals.