Talk:Composite pattern

From Wikipedia, the free encyclopedia

Why do you have to use such an inherently (reading wise) obfuscated language as PERL for your OOP design pattern example? Why not use something that most sane people use for OOP - something such as JAVA, or Python, or Ruby, or... (ad naseum) Don't get me wrong - PERL is a GREAT (!!) language - it just has the problem where it trips over it's own feet by allowing it's code to be so inherently obfuscated (think the PERL Obfuscation contest - or PERL Poetry)...


I added a Java example. Should this talk page now be cleared? Lathspell 21:25, 16 February 2006 (UTC)

This page needs cleanup. It does not feel very encyclopedic.

This has to be one of the most unprofessional UML diagrams I've seen for one of the most common patterns. As per the user above's complaint about the PERL, Java would be a better language, but in interest of neutrality I'd suggest doing the whole thing in a UML sequence diagram to maintain language neutrality. And can't someone with the GoF CD just quote and paste portions outlining the GoF example -- it's much better.

I added two links to discussions on the pattern. What is needed is a realistic example. For instance an example where the pattern is not used and then how refactoring it leads to the pattern. I have found several moderetaly convincing examples on the web but no really convincing one. Concerning language neutrality: UML sequence language is no more neutral than C++ or Java. MikalZiane 12:44, 26 June 2006 (UTC)

added an implementation of the simpler Java-example for ease of reading as opposed to the one given. The old one should probably be removed...

The large code listings of examples are worthless;

  • They're the same thing repeated, if you dont understand it in one language you're not going to understand it in the others. Dont even think about adding more examples. Pseudo code or Java should be sufficient.
  • They dont really show how the pattern maps directly onto code. There should be some explaination or diagrams.

I believe the quality of this article is the code examples as there is nowhere else on the web that both explains the theory and show concrete implementations. A encyclopedia should contain an explanation and history and/or a picture and/or video sequence and/or map and/or examples and/or links to other resources of a given topic. This article only does half and should therefore not be shorten in anyway that will limit the way it elaborate on the topic "Composite pattern". Someone should update (or add) a C# 2.0 example with generics. Also an example in Smalltalk should be added for completeness (a C# 2.0 implementation with the [C5] library and a Java implementation with the Java Collections Framework could also be added). --DotnetCarpenter 09:42, 1 November 2006 (UTC)


The structure section is from "Software Patterns by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides", page 165, 19th print. Almost word to word. Picture is a bit different but also almost the same. Jous 10:28, 31 January 2007 (UTC)

[edit] Bad design

The design of the component class is bad, at least in the diagram and Java, C++, and Prolog examples. I have hard time reading Perl, so I don't comment on it :) Why does the component interface have methods for adding and removing children? Fetching children might by fine, it can simply return an empty list, but the other too really belong to the composite interface. Doing it the way in the article simply complicates the interfaces (the possibility that add and remove don't do anything) and does not make good use of the type system. I read an argument elsewhere for putting these in component: for "transparency". I don't see what kind of transparency this gives. —The preceding unsigned comment was added by 85.2.29.253 (talk) 08:40, 26 February 2007 (UTC).