Public interface icontroller
{
String getname ();
}
Public interface iagginterface
{
String getinnername ();
}
Public class aggregate: iagginterface
{
Public String getinnername ()
{
Return "aggregate ";
}
}
Public class aggregationpattern: icontroller, iagginterface
{
Protected iagginterface aggobj;
Public aggregationpattern ()
{
Aggobj = new aggregate ();
}
Public String getname ()
{
Return "controller ";
}
Public String getinnername ()
{
Return aggobj. getinnername ();
}
}
Class Application
{
[Stathread]
Static void main (string [] ARGs)
{
// Perform a basic operation
Icontroller mycontroller = new aggregationpattern ();
Console. writeline (mycontroller. getname ());
// Perform a basic operation
Iagginterface myaggregate = (iagginterface) mycontroller;
Console. writeline (myaggregate. getinnername ());
// Perform a special operation. Note that the following application is the famous aggregation mode.
Mycontroller = (icontroller) myaggregate;
If (mycontroller! = NULL)
{
Console. writeline (mycontroller. getname ());
Console. writeline ("C # support aggregation pattern ");
}
Else
{
Console. writeline ("C # does not support aggregation pattern ");
}
Console. Read ();
}
}
// Output result