Created
December 29, 2017 16:09
-
-
Save BennieCopeland/5b476f9732c7f8309cfd4ed786525f7b to your computer and use it in GitHub Desktop.
DDD Example
This file contains 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 HouseId : IEquatable<HouseId> | |
{ | |
private readonly string id; | |
public HouseId(string id) | |
{ | |
this.id = id; | |
} | |
public bool Equals(HouseId other) | |
{ | |
return this.id == other.id; | |
} | |
} | |
public class TenantId : IEquatable<TenantId> | |
{ | |
private readonly string id; | |
public TenantId(string id) | |
{ | |
this.id = id; | |
} | |
public bool Equals(TenantId other) | |
{ | |
return this.id == other.id; | |
} | |
} | |
public class IssueId : IEquatable<IssueId> | |
{ | |
private readonly string id; | |
public IssueId(string id) | |
{ | |
this.id = id; | |
} | |
public bool Equals(IssueId other) | |
{ | |
return this.id == other.id; | |
} | |
} | |
public class Name : IEquatable<Name> | |
{ | |
public string FirstName { get; } | |
public string LastName { get; } | |
public Name(string firstName, string lastName) | |
{ | |
this.FirstName = firstName; | |
this.LastName = lastName; | |
} | |
public bool Equals(Name other) | |
{ | |
return this.FirstName == other.FirstName && | |
this.LastName == other.LastName; | |
} | |
} | |
public class Tenant | |
{ | |
public TenantId Id { get; } | |
public Name Name { get; } | |
public Tenant(TenantId tenantId, Name name) | |
{ | |
this.Id = tenantId; | |
this.Name = name; | |
} | |
} | |
public class House | |
{ | |
public HouseId Id { get; } | |
public TenantId CurrentTenantId { get; private set; } | |
public House(HouseId houseId) | |
{ | |
this.Id = houseId; | |
} | |
public void TenantMovedIn(Tenant tenant) | |
{ | |
this.CurrentTenantId = tenant.Id; | |
} | |
public Issue CreateIssue(IssueId issueId, string remarks) | |
{ | |
return new Issue(issueId, this.Id, this.CurrentTenantId, remarks); | |
} | |
} | |
public class Issue | |
{ | |
public IssueId Id { get; } | |
public HouseId HouseId { get; } | |
public TenantId TenatId { get; } | |
public string Remarks { get; } | |
internal Issue(IssueId issueId, HouseId houseId, TenantId tenatId, string remarks) | |
{ | |
this.Id = issueId; | |
this.HouseId = houseId; | |
this.TenatId = tenatId; | |
this.Remarks = remarks; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment