我需要重新设计一个现有的应用程序,其中存在一个仅处理特定类型对象的存储库类。对象的属性和实现仅特定于一种类型。我需要扩展此存储库类的功能,以便它可以处理对具有不同实现的不同对象类型的请求,因为明天可能会有'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
}
}
我认为这个问题不清楚。