• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

HAS-A relation is transitive ?

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess was that it was NOT transitif.

But after some mock exams, I am not sure anymore. As you guess, depending of the version (Whizlabs or K&B), they dont give the same answer. Perhaps it depends of some external factor... ( circular HAS-A, etc. ) ?

Both questions where on a completely theorical situation (ClassA, ClassB, ClassC ... )

Can someone tell me if HAS-A is transitif or not ? And perhaps some exception(s) to the general rule...
[ February 21, 2006: Message edited by: John Smith ]
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the "has a" relationship is not transitive. Just because my class definition "has a" String instance variable, it does not mean that Object.java has a String instance variable.

The "is a" relationship is transitive.
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Keith Lynn:
No, the "has a" relationship is not transitive. Just because my class definition "has a" String instance variable, it does not mean that Object.java has a String instance variable.



To prove your example, after your conclusion, it seems to me that you imply that Object HAS-A MyClass (?!?) since to have your conclusion ( Object HAS-A String ), you should have Object HAS-A MyClass and MyClass HAS-A String

Correct me if I am wrong plz... But It is just an example anyway, if you are sure that HAS-A is NOT transitive, it will be fine for me.
[ February 21, 2006: Message edited by: John Smith ]
 
Keith Lynn
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see your confusion. I think what I was trying to say is that just because a subclass has a String as a member, it does not imply that the superclass has that String as a member.
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok, but for HAS-A transitivity ?

ClassA HAS-A ClassB AND ClassB HAS-A ClassC IMPLY ? ClassA HAS-A ClassC

Really, I can find examples where sometimes you tend to reply YES and sometimes you tend to replay NO... BUT in theory is it a YES or a NO ?
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HAS-A relation is not transitive.

Really, I can find examples where sometimes you tend to reply YES and sometimes you tend to replay NO... BUT in theory is it a YES or a NO ?



Can you give some examples where the answer is YES.
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was also thinking it was NO.

Here, an example for Transitivity
- a house HAS-A kitchen, the kitchen HAS-A oven >>>
the house HAS-A oven

- serialization will take a whole graph of object. if you serialize the house, you will take the whole


Here, an example for no Transitivity
a husband HAS-A wife, the wife HAS-A dress >>>
the husband HAS-A dress ?!? ( you can replace dress by any other personal stuff )


I think it s only the direct instance reference that should be take into account. I am glad I am not the only one who think that.
[ February 22, 2006: Message edited by: John Smith ]
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is is YES.

Here, an example for Transitivity
- a house HAS-A kitchen, the kitchen HAS-A oven >>>
the house HAS-A oven



The above shows that has-a relation is transitive.


Here, an example for no Transitivity
a husband HAS-A wife, the wife HAS-A dress >>>
the husband HAS-A dress ?!? ( you can replace dress by any other personal stuff )



But here what I think is a husband is associated with a wife.
In real life you can't say that:
wife HAS-A dress => the husband HAS-A dress

But in programming point of view every husband object implictly has a dress that belong to wife.
So HAS-A is transitive..

Please let me know where I am wrong.
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really, I dont know...

I tend to say NO because if you say yes, this can lead to an incredible number of HAS-A relations for a class in a random application.

man HAS-A child, child HAS-A illness >>> man HAS-A illness ? No, not really.
husband HAS-A wife, wife HAS-A husband >>> husband HAS-A husband ? Again, no. (I am not sure this one is in the scope of transivity)

Perhaps it is case dependent.

But most question on the subject I have encounter only put random names without any context. And give different answers
[ February 22, 2006: Message edited by: John Smith ]
 
Viv Gupta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here, an example for Transitivity
- a house HAS-A kitchen, the kitchen HAS-A oven >>>
the house HAS-A oven



Lets code this example


Its very clear that although it seems transitive in real world, but not in context of java.

- serialization will take a whole graph of object. if you serialize the house, you will take the whole



Its because you will not like to loose any information while serializing an object
 
Eric Janssens
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Major Wanders,

Great reply. After your example, I think the case is close now

HAS-A is NOT transitive


Thanks !
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic