void Main() { Template ta = new ProductA(); Template tb = new ProductB(); ta.Show(); tb.Show(); } abstract class Template{ public void Show(){ string.Format("Template->{0}",GetName()).Dump(); } protected abstract string GetName(); } class ProductA:Template{ protected override string GetName(){return "A";} } class ProductB:Template{ protected override string GetName(){return "B";} }
时间: 2024-07-31 04:09:13