Skip to content

Instantly share code, notes, and snippets.

@BennieCopeland
Created December 29, 2017 16:09
Show Gist options
  • Save BennieCopeland/5b476f9732c7f8309cfd4ed786525f7b to your computer and use it in GitHub Desktop.
Save BennieCopeland/5b476f9732c7f8309cfd4ed786525f7b to your computer and use it in GitHub Desktop.
DDD Example
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