I'm currently working as a solo developer on my current project. I inherited the project from another developer, who has since left the company. It's a model-view-controller style web application in C#. It uses Entity Framework for object relational mapping. And there are two different sets of classes for the types in the domain model. One set is used for interacting with the ORM and the other is used as the models in the MVC system. For example, there might be two classes as follows:
public class Order{
int ID{get;set;}
String Customer{get;set;}
DateTime DeliveryDate{get;set;}
String Description{get;set;}
}
and
public class OrderModel{
String Customer{get;set;}
DateTime DeliveryDate{get;set;}
String Description{get;set;}
public OrderModel( Order from){
this.Customer= from.Customer;
// copy all the properties over individually
}
public Order ToOrder(){
Order result =new Order();
result.Customer = this.Customer;
// copy all the properties over individually
}
}
I can think of several drawbacks to this approach (more places to change code if something changes, more objects sitting around in memory, more time spent copying data around), but I'm not really sure what the advantages are here. More flexibility for the model classes, I suppose? But I could get that by subclassing the entity classes as well. My inclination would be to merge these two class groups, or possibly have the model classes be subclasses of the entity classes. So am I missing something important here? Is this a common design pattern I'm not aware of? Are there good reasons not to go through with the refactor I'm contemplating?
UPDATE
Some of the answers here are making me realize my initial description of the project was lacking some important details. There is also a third group of classes that exist in the project: the page model classes. They are the ones actually being used as the model backing the page. They also contain information that is specific to the UI, and would not be stored with an order in the database. An example page model class might be:
public class EditOrderPagelModel
{
public OrderModel Order{get;set;}
public DateTime EarliestDeliveryDate{get;set;}
public DateTime LatestAllowedDeliveryDate{get;set;}
}
I totally see the utility of this third group being distinct here, and have no plans to be merging it with something else (though I might rename it).
The classes in the model group are also currently used by the application's API, which I'd also be interested in hearing input on whether that is a good idea.
I should also mention that the customer being represented as a string here was to simplify the example, not because it's actually being represented that way in the system. The actual system has the customer as being a distinct type in the domain model, with its own properties