Validation in Domain Layer

Following JP’s demo code, I made some changes trying to make code more understandable.

  1. Move Rules/RuleSet sub class out from entity class. Make it a seperate class, say MyEntityRules.
  2. Re-write validate() in entity class instead of DomainObject ancestor, because my entity classes are from LinqToSql, it’s hard to intercept entity’s constructor. In this override validate(), I put code like this:

    return MyEntityRules.Default.BrokenBy(this);

  3. Remove unused ruleset field from DomainObject, make validate() in DomainObject throw throw new NotImplementedException();

It works well in my app. It looks like I can easily create more validate method in different situation. e.g, MyEntityRules.High, MyEntityRules.Low, etc…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s