Created
November 28, 2017 04:57
-
-
Save amarwadi/c0fcc289cebc35b566dd6be8e51db3f0 to your computer and use it in GitHub Desktop.
Conversion between Data and Domain Models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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