View RSS Feed

Java Object

HAS-A relationship

Rate this Entry
by , 04-26-2012 at 05:32 PM (4273 Views)
Such relationships are usage based. It shows whether a class consist of HAS-A, certain thing. Code duplication and bugs are reduced by this relationship.

For example:
Java Code:
public class Vehicle{}
public class Speed{}
public class Van extends Vehicle{
	private Speed sp;
}
Class Van HAS-A speed is shown. Speedís separate class doesnít require putting the complete code which has relation with speed, inside the Van class, that makes the reusage of speed class possible in various applications.

In object oriented features, there is no need to worry that which objects does real work. This can be achieved by hiding the implementation details of the Van class from Van class users.
Remember this fact that just one inheritance is supported by the Java. This shows it is not possible to extend more than 1 class. Hence, given below is not legal.
Java Code:
public class extends Animal, Mammal{}
However, one or more interfaces can be implemented by a class.

Submit "HAS-A relationship" to Facebook Submit "HAS-A relationship" to Digg Submit "HAS-A relationship" to del.icio.us Submit "HAS-A relationship" to StumbleUpon Submit "HAS-A relationship" to Google

Categories
Inheritence

Comments