• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does this code will be valid for Composition?  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

this question is related to Composition in Java :




As I think that the Object Integer will be destroyed once this methods execution has been done

So , please let me know if this code will be valid for Composition ??

Inside a Method if I do so

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, because of the compiler error.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote:No, because of the compiler error.
And you ought to know, no for another reason. Tell us why I think "no for another reason".
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean to say that we must use Integer I as an Instance variable but not as local variable .
so thats why it isn't qualified for Composition ??
 
Justin Calleja
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

there's no composition as far as I can tell... composition is ... a class having a reference to an instance of another class.

So Person below has a date of birth.



Inheritance is an IS-A relationship.

So PersonWithDob below is a Person (note that Person is re-defined) but with a date of birth stored as a String:



Something like that.

Regards,

Justin

 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Kiran V wrote:You mean to say that we must use Integer I as an Instance variable but not as local variable .
so thats why it isn't qualified for Composition ??
If you can then say "My Something HAS-AN Integer", then I would accept that as composition.Here a Car HAS-AN Engine. A Car HAS-SEVERAL Wheels. That is obvious. Your example is less obvious, but if you can say that your Something HAS-A Number, then you have presented an example of composition.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!