Understanding the Composite Pattern
page 4 of 9
by David Simmonds
Feedback
Average Rating: 
Views (Total / Last 10 Days): 35956/ 96

Opportunities for and Costs of - Adaptation and Extension

You can add components and clients extremely easily so that extension is truly a breeze. You simply add the new class and inherit appropriately from Composite or Leaf classes. Add the extra-pattern behavior (such as an icon which visually represents the component) and initialize this extra behavior in an appropriate constructor. Document this extra class so that client-coders know that they should make use of it and you are off and running.

Interface issues

The component is an interacting interface and can be implemented as either an interface or a Must-Inherit (abstract class). Practically though, the component is likely to have a fair amount of state which would benefit from the sharing of a constructor. So it is best implemented as a must-inherit class. In fact, in this example, we see where part of the constructor is the addition of a TreeNode class to the nodes collection of an existing treenode. If it were implemented as an interface, then the code for TreeNode manipulation would be spread over many classes and be quite messy and hard to maintain.

Namespace/Scope/Accessor issues

There are no great issues here to be dealt with, except that for ease of understanding by people who maintain your code, participant-classes should be factored into their own assemblies based on component, composite and leaf classes. This makes for ease of maintainability.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-11-29 6:51:31 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search