I will be giving an AOP presentation to the Atlanta .NET user group the 27th at the Microsoft offices in Alpharetta http://www.atlantadotnet.org/. The following is a description of the presentation.
Joe Engineer has been following established concepts for quite some time, he uses TDD, refactors his code often, and even uses design patterns to help reduce coupling within his code. One day in looking at his code Joe came accross the following code ...
public class Customer : MyObjectBase, ISavableObject, IDeletableObject {
private string m_FirstName;
private string m_LastName;
public string FirstName {
get { return m_FirstName; }
set { m_FirstName = value; RegisterDirty(this);}
}
public string LastName {
get { return m_LastName; }
set { m_LastName = value; RegisterDirty(this);}
}
public void Save() {
MyORMapper.Save(this);
}
public void Delete() {
MyORMapper.Delete(this);
}
}
He gives a quick smirk, looks pretty good seems very well factorred ... then he flips over to his order class.
public class Order : MyObjectBase, ISavableObject, IDeletableObject {
private DateTime m_Date;
private string m_LastName;
public string Date{
get { return m_Date; }
set { m_Date = value; RegisterDirty(this);}
}
public void Save() {
MyORMapper.Save(this);
}
public void Delete() {
MyORMapper.Delete(this);
}
}
Joe flips back and forth between these classes for about ten minutes, then he starts flipping to the rest of the domain's classes which look oddly similar. "Something ... smells ... There must be some way to refactor this!" ... Joe the loyal XP'er runs to the kitchen to get some snacks to attract team members to come assist him with his quandry.
"Where have we gone wrong? In looking at the customer class I thought it was very well factorred but when I look at the customer in conjuction with the order I start to smell alot of funny things".
"It seems that we have these little one liners sprinkled through out our entire model, what happens if we need to change how the delete, save or registerdirty works? We have hundreds if not thousands of places doing this; we seem to have fallen prey to copy/paste re-use!"
This presentation includes snacks and is a continuation of Joe's discussion with the team which leads participants through a discovery based learning experience ending up with Aspect Oriented Programming.