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 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