Thinking about avoiding code replication, I got a question that catches me every time I start developing a new system:
Let's say we have a system where I have a customer, have to CRUD it in a repository and show it as a resource in a webservice.
Thinking about the classes related to the customer, we would have (Okay, I will never use these names for real):
- CustomerEntity, representing the entity used for doing the system's logic;
- CustomerRepositoryEntity, representing the table row where it will be stored;
- CustomerXMLEntity, representing the XML node 'customer';
It seems that I will have three entities and all the customer's attributes will be in each class. I was wondering if isn't there a way, or a pattern to consolidate these three classes inside the same entity, called simply "Customer".
This way, every time I need to create a new representation of "Customer" (for example, If I want to represent it as a Json element), i don't need to create a new class for it. I know it's a very particular issue, but I was just wondering if it couldn't be easier (and better looking) than how I am doing now.