I am working on the design phase of a paper folding project. I have a few queries in this. Part of the problem statement says " A web can contain one or more ribbons in it. It can also contain a group of ribbons folded together inside it."

How do you model the association for this? I found two solutions

i) Maintain two associations, one between the web and ribbon and the other between the ribbon
and the Group class. This way, the web contains only ribbons and when you process the ribbons, you'll have to check whether it is part of a group. Note that the behaviour of the ribbon will change if it is part of a group

ii) Introduce a new class called Childelemnt and associate it to web. Both Ribbon and Group will share the interface of Childelement.

Which one do you think is better? If you have any other solution, please let me know.

Thanking you all in advance,


  • 1
    Can a ribbon be in a Web as well as Group? Can Groups contain other Groups? Can a Group contain anything else?
    – R Sahu
    Commented Jul 30, 2014 at 3:45
  • All the ribbons are contained inside the web. But the point is, if a number of ribbons are grouped together, then their behaviour will be different from the normal ones. A group can not contain other groups. Groups contain only ribbons and nothing else...
    – Pradeep
    Commented Jul 30, 2014 at 9:51

1 Answer 1


It makes sense for objects to share an interface if they share operations or properties. In your case, both ribbons and groups can be part of a web, so it makes sense for then to share an interface, which is your second option (which is sometimes called the composite pattern). I recommend calling that interface WebElement.

There are some added complexities, like the fact that a ribbon can be part of the web, a group, or (conceivably) unattached. You'll need logic to enforce those rules. Since ribbons can be members of webs and groups, then you will likely have to maintain two associations, as you mention in your first option, but the two are unrelated to each other, and are a consequence of your system having two types of container (web and group).

Lastly, to alter the behavior of a ribbon depending on whether it is part of a group or not, you might want to employ the strategy pattern.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.