Reputation: 51
In Java every class is a child of Object. So a class IS-A Object. Now if it contains a data member of Object type (actually any type in this case), then it would be HAS-A relationship. Related to above statement I have following doubts. 1. Is there a name for this relationship, IS-A and HAS-A coming together? 2. Are there any real world example for it? 3. From OOPS perspective, is it okay to have this relationship or should be avoided?
Upvotes: 2
Views: 250
Reputation: 11992
- Is there a name for this relationship, IS-A and HAS-A coming together?
No.
- Are there any real world example for it?
List<Set> aListThatContainsSets
List and Set are both Collections. In this example a List has a bunch of Sets.
- From OOPS perspective, is it okay to have this relationship or should be avoided?
Yes its fine. You can even HAS-A yourself.
public class MyClass{
MyClass me;
}
Upvotes: 2