Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Composite and java.awt.Component / Container

 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Day,

I'm looking at the java.awt.Component class and its subclass java.awt.Container and wondering whether we can consider them parts of a Composite design pattern.

java.awt.Component is an abstract class and java.awt.Container is a concrete class as Composite requires.

Any thoughts?

Thanks,
Dan
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but with a "hierarchical" flavor. Normally composites are groupings of similar things, but in this scenario, the component-to-container is a parent-child relationship.

HTH
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ajith.
 
D. Rose
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but with a "hierarchical" flavor.


Ajith,

Aren't composite used to "Compose objects into tree structures to represent part-whole hierarchies."
What do you mean by "flavor"?
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I perceive the general idea of a Composite as a part-whole implementation and not necessarily every such implementation results in a hierarchical, parent-child, tree-like structures. In fact, I believe that the tree-like representation is a special scenario where each component can also be a composite. That's why I used the qualifier "flavor".

For instance, I can model a complex "Clock" object as a composite of "Wheels". I chose the Composite implementation because I perceive the Clock as a whole and a group of Wheels as the parts, and additionally, that life of the Wheel object(s) has no scope outide that of the "Clock" object. As you can see, there is no real hierarchy here, just a part-to-whole relationship.

HTH
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic