Rules for Object Composition

I have found the following rules make reuse easier:

  1. Contained objects should not be aware of the container.
  2. Containers should be aware of the contents.
  3. Event handlers should be used for communication from the contained to the container.
  4. Inter object event handlers should be established by the Container and should be explicitly set up in code.

These simple rules permit reuse of the contained control.  Objects developed along these lines are much easier to extend and reuse.  It also makes it very quick to rearrange the top level container. 

These rules also apply recursively so that a container may be contained in an outer container. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s