DesignPattern_Behavioral_Strategy

void Main()
{
    Product product = new Product();
    product.Set(new ShowA());
    product.Show();
    product.Set(new ShowB());
    product.Show();
}

class Product{
    IShow ishow;
    public void Set(IShow isw){ishow=isw;}
    public void Show(){
        ishow.Show();
    }
}
interface IShow
{
    void Show();
}
class ShowA:IShow{
    public void Show(){}
}
class ShowB:IShow{
    public void Show(){}
}
时间: 2024-10-11 11:46:24

DesignPattern_Behavioral_Strategy的相关文章