By Smart object I consider any Domain object that knows its original property value if property is altered. Smart objects usually have a base class and implement properties by using GetPropertyValue/SetPropertyValue methods. On the other hand POCO objects would commonly have no base class and implement simple properties.
public class SmartObject : BaseDomainObject
{
public int id
{
get { return (int)this.GetPropertyValue("Id"); }
set { this.SetPropertyValue("Id", value); }
}
}
public class POCO
{
public int id { get; set; }
}
I like Smart object because it does a lot of hard work for me. I can easily add all those useful features to BaseDomainObject and have them in all my derived Domain classes:
- common properties (like Id, Status...)
- object state tracking (new, modified, unchanged)
- all properties raise events on property changes (implementation of INotifyProperyChanged)
- derived classes can be automatically be serializable (although I rarely find this useful)
- I can have all this other behavior that can be useful - Clone/Sync/ IsPropertyDirty...
On the other hand POCO's are super simple and have no dependency to any base class.
Nowadays I here a lot of POCO praising because:
- it can be sent over the wire (usually to web browser as JSON)
- it is pure
On the other hand I think that reasons above are fallacy because:
- DTO's are for wire transfer and not domain objects. Behavior encapsulating data if lost when domain object is serialized to JSON.
- this chase for purity seams like chase for even more anemic domain model which doesn't have logic nor anything smart attached to it.
With all this sad, I still like that POCO and it bugs me. What is your opinion?