• Post Reply Bookmark Topic Watch Topic
  • New Topic

a strange auto-relation class  RSS feed

 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Could anyone explain to me what kind of relation it is? Why a class can have an instance variable of herself? What is it useful for? I mean in real life application!

Thanks,

Enrique Villamiza
 
Craig Tyler
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a plain old has-a relationship. Although it's a little bit more involved than this example, a common real life application use for this would be the Decorator Design Pattern.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or an even simpler purpose: imagine that A is a link in a chain. Each link holds a reference to the next link; the last link holds "null", no link.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!