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. 

Boo and MSBuild

Msbuild is microsofts answer to Ant. This is a build tool for the .Net Platform.

It has the minor benfit of being the native file format of the Visual Studio 2005 project files.

You need the .Net Framework 2 installed and to add the Microsoft Framework to your path statement

Boo is a lightweight .Net language.

Here is a sample that gets a task written in Boo for msbuild:

=== MyTask.boo ===

import Microsoft.Build.Framework
import Microsoft.Build.Utilities
import Boo.Lang

class MyTask(Task):
public override def Execute():
Log.LogMessage(MyProperty)
return true

private _MyProperty as string

MyProperty as string:
get:
return _MyProperty
set:
_MyProperty = value

=== Test.proj ===

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
DefaultTargets="MyTarget"
InitialTargets="BuildMyTask"
>

<Target Name="BuildMyTask">
<Exec command="booc MyTask.boo -t:library"/>
</Target>

<UsingTask TaskName="MyTask" AssemblyFile="MyTask.dll"/>

<Target Name="MyTarget">
<MyTask MyProperty="Hello!"/>
</Target>
</Project>

===

You also need Boo installed (and on your path).
Copy Boo.Lang into the directory that you created these scripts in.

At the command line type: msbuild
This will build and run the minimal boo task.
I am planning to add a real msbuild task for boo.