I am trying to apply DDD in one of the applications that I am currently working on, and I cannot say that I understood this 100%.
In most of the examples that I look at, it seems that we are trying to avoid public settings on the properties of the essence of the domain. For example, I see domain objects implemented as shown below:
public class Product
{
public Product(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
Name = name;
}
public string Name { get; private set; }
public void UpdateName(string newName)
{
if (newName == null)
{
throw new ArgumentNullException("newName");
}
Name = newName;
DomainEvents.Raise(new ProductNameUpdatedEvent(this));
}
}
Usage will look something like this:
product.UpdateName("foobar");
However, I can achieve the same behavior by embedding update logic in the Namesetter property, as shown below:
public class Product
{
private string _name;
public Product(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
_name = name;
}
public string Name
{
get
{
return _name;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_name = value;
DomainEvents.Raise(new ProductNameUpdatedEvent(this));
}
}
}
In this case, the usage will look something like this:
product.Name = "foobar";
, , . , , ? DDD, -, ?