I'm trying to split the use of a business entity (e.g. a post) thought an application uses, trying to obtain a clean architecture
So I will likely have:
- A class model, where the business logic lives
class Post {
private text: string;
public constructor(text: string){
this.text = text;
}
public getText(){
return this.text;
}
public setText(text: string){
this.text = text;
}
public clearText(){
this.text = '';
}
}
- An interface for data transfers
interface PostDTO {
text: string
}
- And an interface for the data access (imagine this like a class highly dependent on an ORM framework)
interface PostDAO {
schema: {
text: string
}
}
I got several pros in doing this:
- Isolation in business logic, I'm able to write pure unit tests without the use of DB, etc.
- Complete control of who receives what (e.g. a client can receive formatted data from the application or a database can save entity fields according to its available types)
- Use of repository pattern, the clients (like controllers) that use the repository will receive always pure classes with business logic that clients can use
However, what bothers me is the amount of work required to make a small change in a model, while saying adding a field
Assume that I want the application to manage authors along with posts, I would have to:
- Edit model adding the author field, with changes to the unit tests
- Changing how an author is saved and loaded between the model and the DTO (I usually keep an intermediary mapper class, in this way the application is not dependent on which data source is used and how, if this change I just have to write another mapper class that know about the new data source driver/ORM)
- Change the ORM schema, modify and test integration tests
- Change DTO interface, modify and test integration tests
I'm doing this for a while and I'm perfectly fine with it but:
- Am I doing this terribly wrong and I don't know it?
- Can I simplify this process? (Note that this question want to be agnostic about magic frameworks and DBs)
- Am I (gulp) missing something in this process?