delegation vs aggregation vs consultation
What is the difference between these terms, can you give please small exampl开发者_高级运维es?
Aggregation: From http://en.wikipedia.org/wiki/Aggregate_pattern
In Design Patterns, an aggregate is not a design pattern but rather refers to an object such as a list, vector, or generator which provides an interface for creating iterators.
Meaning in short on elements contains 0 or more other elements of another type.
public class MyAggregation
{
protected List<MyAggregates> aggregates = new List<MyAggregates>();
public void add( MyAggregate element )
{
aggregates.Add( element );
}
}
Delegate: From http://en.wikipedia.org/wiki/Delegation_pattern
In software engineering, the delegation pattern is a design pattern in object-oriented programming where an object, instead of performing one of its stated tasks, delegates that task to an associated helper object
Meaning that some class uses another object to do something.
public interface IExceptionHandler
{
void handle( string filename );
}
public class FileDeleteExceptionHandler : IExceptionHandler
{
public void handle( string filename )
{
File.Remove( filename );
}
}
public class MyExceptionHandler
{
protected IExceptionHandler exceptionHandler;
public MyExceptionHandler( IExceptionHandler theHandler )
{
this.exceptionHandler = theHandler;
}
public void handleException( string filename )
{
excpetionHandler.handle( filename );
}
}
Or in C# delegation can just refer to a delegate function, see http://msdn.microsoft.com/de-de/library/900fyy8e%28VS.80%29.aspx
Consultation I know nothing off, sorry
hth
Mario
Note: I did not actually compile the code above.
There is a description of the difference between delegation and consultation here.
It would seem that what most folks refer to as delegation might more properly be referred to consultation.
I guess that delegation in the more formal sense described in the reference would be implemented as an Abstract base class delegating to a Concrete class.
Delegation, Aggregation and Consultation are not design patterns. They are concepts helps us to describe Design patterns. for more
Composition is a way to combine simple objects or data types into more complex one i.e. as a single unit. Compositions are a critical building block of many basic data structures
Aggregation differs from ordinary composition in that it does not imply ownership. In composition, when the owning object is destroyed, so are the contained objects. In aggregation, this is not necessarily true
Delegation is the simple yet powerful concept of handing a task over to another part of the program. In object-oriented programming it is used to describe the situation where one object assigns a task to another object, known as the delegate
Consultation in object-oriented programming occurs when an object's method implementation consists of a message send of the same message to another constituent object.
wiki: Delegation Composition Consultation
精彩评论