mercredi 26 février 2020

Enforcing DRY through the use of two almost identical generic db access classes

Suppose that I have a business logic layer, in which I have made something similar to a repository pattern. Each class in my repository extends the same generic class, in which i have basic CRUD operations.

I have run into a problem, where I need to write the same logic for the tables in my database, where I have a many-to-many relationship - which I probably have 5 places in my ORM.

Initially, I thought about putting this logic inside the generic class to enforce DRY - However, this may be a very bad idea, since my non-many-to-many tables will be able to access these specific methods as well.

Another approach, would be to include this logic within each of my repository classes, meaning that i then would have to repeat my code - naturally I don't like that.

Therefore, this is more of a design question. But I would really like to know, how you believe this could be solved in order to make my code as clean as possible.

Aucun commentaire:

Enregistrer un commentaire