重新设计存储库类,使其处理请求对象的不同实现

问题描述 投票:0回答:1

我需要重新设计一个现有的应用程序,其中存在一个仅处理特定类型对象的存储库类。对象的属性和实现仅特定于一种类型。我需要扩展此存储库类的功能,以便它可以处理对具有不同实现的不同对象类型的请求,因为明天可能会有'n'个此类对象。

有人可以建议进行重新设计的最佳方法是什么。

现有设计如下:

class SomeClass
{
  string colour {get; set;}
  string type {get; set;}
}


class Service : IService

public void DoWork()
{
    Repository repo = new Repository();
    repo.DoRepoWork();
}

public void DoSomeOtherWork()
{
   Repository repo = new Repository();
   repo.DoSomeOtherRepoWork();
}

class Repository : IRepository
{
  public void DoRepoWork()
  {
     SomeClass obj = new SomeClass();

     obj.Color = "Blue";
     obj.Type = "Line";

     //Implementation specific to only one type of SomeClass Object

  }

  public void DoSomeOtherRepoWork()
  {
     SomeClass obj = new SomeClass();

     obj.Color = "Blue";
     obj.Type = "Line";

     //Implementation specific to only one type of SomeClass Object

  }
}
c# design-patterns service repository-pattern design
1个回答
0
投票

我认为这个问题不清楚。

  1. 您是否期望多种IService?即不同类型的iService类。
  2. 您是否期望每种IService都进行不同类型的回购工作?即repoWork(),DoSomeOtherRepoWork()
  3. 什么是SomeClass。每个回购工作方法是否都有自己的SomeClass对象?有什么关系?
© www.soinside.com 2019 - 2024. All rights reserved.