public interface IMovable
{
void Move();
}
public interface IUnloadable
{
void Unload();
}
public class Vehicle : IMovable
{
public void Move()
{
Console.Write("moving");
}
}
public class Truck : IMovable, IUnloadable
{
private Vehicle Veh;
public Truck(Vehicle veh)
{
this.Veh = veh;
}
public void Move()
{
Veh.Move();
Console.Write("reverse with beepy noise as well");
}
public void Unload()
{
Console.Write("Unload");
}
}
If this is the decorator pattern. What is the difference between the decorator pattern and composition? I seen examples of this pattern where there is inheritance used. For instance the java example on wikipedia but I dont see the need to use inheritance at all, or am I missing something?
Aucun commentaire:
Enregistrer un commentaire