As explained in the first part of this article series generic implementation of Visitor pattern involves usage of delegates and anonymous methods.
The Visit method invokes the algorithm processing using anonymous methods.
public class GenericVisitor
{
private IEnumerable
public GenericVisitor(IEnumerable
{
_enumerableT = elements;
}
public void Visit(Action
{
foreach (T element in _enumerableT)
{
callback.Invoke(element);
}
}
}
Which can be used as
GenericVisitor<IElement> carVisitor = new GenericVisitor<IElement>(car.carElements);
carVisitor.Visit(delegate(IElement element)
{
Console.WriteLine(element.ToString());
});
No comments:
Post a Comment