抽象工厂设计模式-C#

抽象工厂设计模式-C#,c#,design-patterns,C#,Design Patterns,我为《工厂设计模式》阅读了这篇精彩的文章: 我非常理解这个例子。你能给我举个同样的例子吗 抽象工厂设计模式 我想了解抽象工厂设计模式的基本概念 感谢您--虽然不是同一个示例,但很容易理解。commom构造是一个抽象工厂,用于创建数据访问组件,您可以为数据库供应商或其他存储库系统实现每个工厂 using System; namespace DZoneArticles.FactoryDesignPattern { public abstract class EmployeeFactory

我为《工厂设计模式》阅读了这篇精彩的文章:

我非常理解这个例子。你能给我举个同样的例子吗

抽象工厂设计模式

我想了解抽象工厂设计模式的基本概念


感谢您--虽然不是同一个示例,但很容易理解。

commom构造是一个抽象工厂,用于创建数据访问组件,您可以为数据库供应商或其他存储库系统实现每个工厂

using System;
namespace DZoneArticles.FactoryDesignPattern
{
    public abstract class EmployeeFactory
    {
         public abstract Employee Create();
    }
    public class DBAFactory : EmployeeFactory
    {
         public override Employee Create() { return new DBA(); }
    }
    public class ManagerFactory : EmployeeFactory
    {
         public override Employee Create() { return new Manager(); }
    }
}
改编自“应用的Java模式”:


C#中抽象工厂设计模式的简单示例:


-1这应该进行研究,特别是考虑到目前为止的答案只是一个链接。我需要使用我提供的相同示例来抽象工厂设计模式,以便更好地理解它。你可以修改代码/扩展代码。我知道界面保持不变。还有那些课程。我们可以将程序员和高级程序员归为开发人员,将网络DBA归为网络DBA,将SQLServerDBA归为DBA。现在我认为我们可以基于此创建工厂类。
 public interface IEmployee
 {
 }

 public class Developer : IEmployee
 {
 }

 public class Tester : IEmployee
 {
 }

 public interface IManager
 {
 }

 public class HRManager : IManager
 {
 }

 public class ProjectManager : IManager
 {
 }

 public interface IFactory()
 {
      IEmployee CreateEmployee();
      IManager CreateManager();
 }

 public class ConcreteFactory1 : IFactory
 {
      public IEmployee CreateEmployee()
      {
           return new Developer();
      }

      public IManager CreateManager()
      {
           return new HRManager();
      }
 }

 public class ConcreteFactory2 : IFactory
 {
      public IEmployee CreateEmployee()
      {
           return new Tester();
      }

      public IManager CreateManager()
      {
           return new ProjectManager();
      }
 }
using System;
using System.IO;

enum TYPE_OPERATION
{
    Design,
    Work
}

//Abstract Factory
abstract class AbstractFactory
{
    public static AbstractFactory PrepareOperation(TYPE_OPERATION type_operation)
    {
        switch (type_operation)
        {
            case TYPE_OPERATION.Design:
                return new DesignTeam();

            case TYPE_OPERATION.Work:
                return new WorkTeam();
            default:
                throw new NotImplementedException();
        }
    }

    public abstract void PerformOperation();
}

class DesignTeam : AbstractFactory
{
    public override void PerformOperation()
    {
        Designers m = new Designers();
        m.Designing();
    }
}

class WorkTeam : AbstractFactory
{
    public override void PerformOperation()
    {
        Workers k = new Workers();
        k.Working();
    }
}

// The concrete class
class Designers
{
    public void Designing()
    {
        Console.WriteLine("The Design Team has completed its work!");
    }
}

// The concrete class
class Workers 
{
    public  void Working()
    {
        Console.WriteLine("The Work Team has finished its work!");
    }
}
public class Client
{   
    public static void Main(String[] args)
    {
        AbstractFactory factory = AbstractFactory.PrepareOperation(TYPE_OPERATION.Design);
        factory.PerformOperation();

        factory = AbstractFactory.PrepareOperation(TYPE_OPERATION.Work);
        factory.PerformOperation();

        Console.ReadLine();
    }
 }
/* output:
 The Design Team has completed its work!
 The Work Team has finished its work!
*/