IS-A relationship
Inheritance is provide us the re-usability feature. Let's take one example we have a Human Category, so either boy can be human or girl can be human and each human has some common activity like eat(), walk(), see() apart from common activity boy has some activity like run() similarly girl has skip() and cookFood().
see more detail on below diagram-
So Boy and Girl both denoted by Human in common. and this is called inheritance and this relationship human--boy and human --girl called IS-A relationship. so in short you can say Boy IS-A Human similarly Girl Is-A Human. so IS-A relationship always give re-usability feature.And In java we can achieve either by extends(In case of class) keyword or implements(in case of interface).
in this case we will say Boy-------------->Human
Has-A relationship (Association)
Has-A means an instance of one class “has a” reference to an instance of another class or another instance of same class.There is no specific keyword to implement HAS-A relationship but mostly we are depended upon “new” keyword.
It can be two type-
- Aggregation
- Composition
In UML it is graphically represented as a hollow diamond shape on the containing class end of the tree with a single line that connects the contained class to the containing class. The aggregate is semantically an extended object that is treated as a unit in many operations, although physically it is made of several lesser objects
class Car {
Headlight headlight = new Headlight();
............
...............
}
Composition means strong has-a relationship between object. for example car and engine, if engine is removed then car can not run. That means if both object are tightly associated hence this makes strong relationship between object.In other word Composition usually has a strong life cycle dependency between instances of the container class and instances of the contained class(es): if the container is destroyed, normally every instance that it contains is destroyed as well. (Note that, where allowed, a part can be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite.)
The UML graphical representation of a composition relationship is a filled diamond shape on the containing class end of the tree of lines that connect contained class(es) to the containing class.
class Car {
Engine engine = new Engine();
...................
..................
}
This comment has been removed by the author.
ReplyDeleteIf you're a novice, you can easily get a scan tool for your car. Alternatively, a professional can purchase a scanner for his or her home use. Author is an expert of total car diagnostics, go here for more interesting information.
ReplyDeleteJava Class By Rk: Java - Is-A And Has-A Relationship Or Inheritance Vs Association (Composition And Aggregation) >>>>> Download Now
ReplyDelete>>>>> Download Full
Java Class By Rk: Java - Is-A And Has-A Relationship Or Inheritance Vs Association (Composition And Aggregation) >>>>> Download LINK
>>>>> Download Now
Java Class By Rk: Java - Is-A And Has-A Relationship Or Inheritance Vs Association (Composition And Aggregation) >>>>> Download Full
>>>>> Download LINK