lundi 26 février 2018

Building architecture on top of abstraction

I am developing a .NET Core Web API project and experiencing the following issue:

I have a simple domain of one base class and three derived classes. For simplicity let me name them in the following manner - Design1, Design2, Design3 and the abstract class Design

public abstract class Design { }
public class Design1 : Design { }
public class Design2 : Design { }
public class Design3 : Design { }

I have created repositories for every class except the abstract one and now I am trying to figure out how to structure my business logic and the controllers. But first let me go a bit deeper in the structure of the application

The data from the client is sent in a data transfer object. Let me call it DesignDTO. There, I have a property named type which has the value of either Design1, Design2 or Design3

public class DesignDto{
    // some other properties
    public string type; //has value of Design1, Design2 or Design3
}

This object is sent to the Post method of the design controller and here is the tricky part. The DesignDTO should be mapped to one of the derived objects. I do this with a factory method depending on the value of the type property. Then, I do the same when I call the business logic class - the business logic classes of all derived classes share the same IDesignLogic interface.

public class Design1Logic : IDesignLogic{
    public void add(Design design){
        // some logic
    }
}

public class Design2Logic : IDesignLogic{
    public void add(Design design){
        // some logic
    }
}

So my question is if this is a proper manner of structuring the application?

I've considered creating one business logic class - DesignLogic that will be responsible for all the logic in the derived classes. Later decided it will become complicated and I will still have to do the factory when calling the repositories.

My other though was creating controllers for every derived class, then separate business logic and repository, but this way the point of the abstraction will be lost and scalability of the application will be 0.

What are your thoughts about this issue? I am glad to hear more about it.

Aucun commentaire:

Enregistrer un commentaire