This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Using AO to handle roles
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Adrian Colyer (man he is on a role since he started a blog!), has just written about the classic mixed-role cohesion problem.
This is explained in the book Fundamentals of Object-Oriented Design in UML.
The example revolves around a Person and a Dog. You don't want to tie them together directly, as what about tying a Person and their house, phone, tv, spouse, etc. It never ends.
This is the classic problem with roles.
Adrian shows that his adverb/adjective analogy can fit in here, and in fact we want to create a dog-owning person in this case. However we don't want them tied, as we also may want an organization that owns dogs etc.
He spells out an elegant way to use AO, and intratype declarations (mixins) to do the job nicely!
/**
* not a person in sight...
*/
public aspect DogOwnership {
public interface IDogOwner {};
private int IDogOwner.numDogsOwned;
public int IDogOwner.getNumDogsOwned() { return numDogsOwned; }
}
public aspect PersonOwnsDog {
declare parents : Person implements DogOwnership.IDogOwner;
}
This is why I wanted Anders to allow for mixins in C# :)
Read Adrian in Person owns Dog....