Differentiation between Inheritance and Aggregation
Hi All,
I have too many confusion about the various java concepts. I have some knowledge about the Inheritance. But the thing is that I don't know anything about the difference between Inheritance and Aggregation. I know inheritance is used for to implement the re-usability of program code. But but not able to get the differentiation between Inheritance and Aggregation. I wonder if you are able to help me to understand this.
Re: Differentiation between Inheritance and Aggregation
The concept of inheritance is one of the most important concept of object oriented programming because it irreversibly determines the manner in which a code Java is written. Inheritance is a mechanism to create a new class from an existing class in him uttering his properties and methods. In this way, the inherited classes form a hierarchy descending on top of which is the base class.
Re: Differentiation between Inheritance and Aggregation
It is sometimes difficult to choose between classical association and aggregation. An aggregation is a special relationship between an object and several objects the component. An aggregation is sometimes called aggregation of reference as opposed to aggregation by value (also called composition). An aggregation is represented by an empty diamond positioned on the side of the compound (the class representing the whole).
Re: Differentiation between Inheritance and Aggregation
A composition is an aggregation constraint. The additional constraint compared to a traditional aggregation is relative to the lifetime of objects. The composition implies that components are dependent existence of the compound. A composition is also called aggregation by value. A "implements" Java is represented by an inheritance relationship but with a dotted arrow. To define a new class, we only need to inherit the an existing class and add new methods.
Re: Differentiation between Inheritance and Aggregation
Following is example of Aggregation:
Quote:
class Ai (
private Bi objBi;
...
)
//If Class Bi is used primarily in the context of Ai, you can also opt for an inner class:
public class Ai
(
private Atti1;
private class Bi
(
att_de_Bi_1 string;
)
)
Re: Differentiation between Inheritance and Aggregation
When instantiating a class, it inherits all properties and methods of its super-class, which itself inherits a possible super-class. By default a class inherits from the super-super-class "named Object. To inherit a class from a super-class, Java provides the keyword 'extends', The main job of the Java programmer is to design a class hierarchy, that is to say, organizing classes such as the properties and methods common to several classes are placed in a super-class.