dimanche 18 juin 2017

How can this class be designed better?

We have a Web API library, that calls into a Business/Service library(where our business logic is located), which in turn calls a Data access library (Repository).

We use this type of data transfer object all over the place. It has a "Payers" property that we may have to filter (meaning, manipulate its value). I have gone about implementing that check as such, but it feels dirty to me, as I'm calling the same function all over the place. I have thought about either:

  1. Using an attribute filter to handle this or
  2. Making the RequestData a property on the class, and do the filtering in the constructor.

Any additional thoughts or design patterns where this could be designed more efficiently:

public class Example
{
    private MyRepository _repo = new MyRepository();

    private void FilterRequestData(RequestData data)
    {
        //will call into another class that may or may not alter RequestData.Payers
    }

    public List<ReturnData> GetMyDataExample1(RequestData data)
    {
        FilterRequestData(RequestData data);
        return _repo.GetMyDataExample1(data);
    } 

    public List<ReturnData> GetMyDataExample2(RequestData data)
    {
        FilterRequestData(RequestData data);
        return _repo.GetMyDataExample2(data);
    } 

    public List<ReturnData> GetMyDataExample3(RequestData data)
    {
        FilterRequestData(RequestData data);
        return _repo.GetMyDataExample3(data);
    } 
}


public class RequestData
{
    List<string> Payers {get;set;}  
}

Aucun commentaire:

Enregistrer un commentaire