Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created January 25, 2023 22:05
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 dcomartin/683c458474a369d9f7b24841fd338811 to your computer and use it in GitHub Desktop.
Save dcomartin/683c458474a369d9f7b24841fd338811 to your computer and use it in GitHub Desktop.
public class Product : Entity, IAggregateRoot
{
public string Name { get; private set; }
public decimal Price { get; private set; }
public Product(string name, decimal price)
{
Name = name;
Price = price;
}
public void SetName(string name)
{
Name = name;
}
public void SetPrice(decimal price)
{
Price = price;
if (!new ProductNegativePriceSpecification().IsSatisfied(this))
{
throw new DomainException("Product Price must be greater than zero.");
}
}
}
public class ProductNegativePriceSpecification
{
public bool IsSatisfied(Product entity)
{
return entity.Price > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment