The advantage of being able to assume tooling Throwing away code again with Groovy
May 28

Using AO to handle roles

Tech Add comments

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….

Leave a Reply

Spam is a pain, I am sorry to have to do this to you, but can you answer the question below?

Q: Type in the word 'cricket'