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

2 replies on “jpatterns”

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

Comments are closed.