Interface, Event, Wrapper
Code
//an interface
public interface IOperator
{
event EventHandler OperationCompleted;
void Operate();
}
//a base implementation
public class OperatorBase : IOperator
{
public event EventHandler OperationCompleted;
public virtual void Operate()
{
throw new Exception("Not implemented");
}
protected virtual void OnOperationCompleted(EventArgs e)
{
if(this.OperationCompleted)
{
this.OperationCompleted(this, e);
}
}
}
// a wrapper base
public class OperatorWrapperBase : IOperator
{
IOperator mWrappee;
public OperatorWrapperBase(IOperator wrappee)
{
this.mWrappee = wrappee;
}
public IOperator Wrappee { get {return mWrappee;} }
public virtual void Operate()
{
this.Wrappee.Operate();
}
public event EventHandler OperationCompleted
{
add { this.Wrappee.OperationCompleted+=value; }
remove { this.Wrappee.OperationCompleted-=value; }
}
}
//an interface
public interface IOperator
{
event EventHandler OperationCompleted;
void Operate();
}
//a base implementation
public class OperatorBase : IOperator
{
public event EventHandler OperationCompleted;
public virtual void Operate()
{
throw new Exception("Not implemented");
}
protected virtual void OnOperationCompleted(EventArgs e)
{
if(this.OperationCompleted)
{
this.OperationCompleted(this, e);
}
}
}
// a wrapper base
public class OperatorWrapperBase : IOperator
{
IOperator mWrappee;
public OperatorWrapperBase(IOperator wrappee)
{
this.mWrappee = wrappee;
}
public IOperator Wrappee { get {return mWrappee;} }
public virtual void Operate()
{
this.Wrappee.Operate();
}
public event EventHandler OperationCompleted
{
add { this.Wrappee.OperationCompleted+=value; }
remove { this.Wrappee.OperationCompleted-=value; }
}
}