lundi 13 avril 2020

Redesign repository class such that it handles different implementations of request objects

I need to redesign an existing application where there is a repository class handling only specific type of object. The object's properties and implementation are specific to only one type. I need to extend the capability of this repository class such that it can handle requests for different object types having different implementations as tomorrow there can be 'n' number of such objects.

Can someone suggest as to what would be the best way to have such redesign.

The existing design is like below :

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

  }
}

Aucun commentaire:

Enregistrer un commentaire