jpatterns

We have tried different approaches to specifying the patterns. The current favorite is to use inner annotations for specifying the roles.

So, instead of our earlier approach:

@CompositePattern(role = CompositeRole.COMPONENT, participants =
  {DistributionList.class, Person.class})
public abstract class Contact {
  public abstract void sendMail(String msg);
  public void add(Contact contact) {}
  public void remove(Contact contact) {}
}

We want to do the following:

@CompositePattern.Component
@PatternParticipants({DistributionList.class, Person.class})
public abstract class Contact {
  public abstract void sendMail(String msg);
  public void add(Contact contact) {}
  public void remove(Contact contact) {}
}

I think that is easier to read and understand.

Would love to hear your opinions on this.

Heinz

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to jpatterns

  1. jonnybbb says:

    I really like the inner annotations approach, although it might have one downside: The user does not have code completion hints to find out that a @PatternParticipants should be used in conjunction with the concrete pattern.
    I already started using it for the exercises! Great.

  2. admin says:

    Yes, we agree. Unfortunately annotations do not have inheritance, which means we would have to include the Class[] participants() default {}; attribute in every single inner annotation. I can whack that in with vi if you feel it should be there rather. Then we could do the following:

    @CompositePattern.Component(participants={DistributionList.class, Person.class})
    public abstract class Contact {
    public abstract void sendMail(String msg);
    public void add(Contact contact) {}
    public void remove(Contact contact) {}
    }

    Heinz