Skip to content

Instantly share code, notes, and snippets.

@amarwadi
Created November 28, 2017 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarwadi/c0fcc289cebc35b566dd6be8e51db3f0 to your computer and use it in GitHub Desktop.
Save amarwadi/c0fcc289cebc35b566dd6be8e51db3f0 to your computer and use it in GitHub Desktop.
Conversion between Data and Domain Models
public class GoodDomainModel
{
public string Id {get; protected set; }
public Name Name {get; protected set; }
private GoodDomainModel(string id, Name name)
{
Id = id;
Name = name;
}
//Direct dependency between Data model and domain model - Can this be eliminated?
public static GoodDomainModel Create(BadDataModel dataModel)
{
var d = new GoodDomainModel(dataModel.Id, new Name(dataModel.FirstName, dataModel.LastName);
return d;
}
}
//Overly simplified example of a bad Data model. In reality, this has many nested/redundant items
//that are being saved to facilitate read model (which wasn't a good idea)
public class BadDataModel
{
public string Id {get; set; }
public string FirstName {get; set;}
public string LastName {get; set;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment