小编nan*_*nda的帖子

使用Generics-C#的工厂方法模式

我正在学习Generics.当我有一个抽象方法模式时:

//Abstract Product
interface IPage
{
    string pageType();
}

//Concerete Product 1
class ResumePage : IPage
{
    public string pageType()
    {
        return "Resume Page";
    }
}

//Concrete Product 2
class SummaryPage : IPage
{
  public string pageType()
  {
    return "SummaryPage";
   }
}

//Fcatory Creator
class FactoryCreator
{
   public IPage CreateOnRequirement(int i)
    {
      if (i == 1) return new ResumePage();
      else { return new SummaryPage(); }
    }
}


//Client/Consumer

void Main()
{

  FactoryCreator c = new FactoryCreator();
  IPage p;
  p = …
Run Code Online (Sandbox Code Playgroud)

c# generics design-patterns

4
推荐指数
1
解决办法
4860
查看次数

标签 统计

c# ×1

design-patterns ×1

generics ×1