3

I'm implementing a Linear Planner with a stack of goals in Java. For that reason I'm using a Stack in which I need to store different objects: predicates, operators, states. To achieve this, I created an Interface called Stackable, so I have a Stack<Stackable>. This interface is empty as there's nothing that all stackable objects have in common, except that all of them have to be stacked.

public Interface Stackable {

}

public class Predicate implements Stackable {
    private String name;
    private List<Parameter> params;
    ...
}

public class Operator implements Stackable {
    private String name;
    private List<Parameter> params;

    private List<Predicate> preconditions;
    private List<Predicate> adds;
    private List<Predicate> deletes;
    ...
}

public class State implements Stackable {
    private List<Predicate> preds;
    ...
}

As I didn't like the idea of an empty interface, I started reading and came accross with the term Marker interface, which I think is the case of my Stackable. I also found that they can be replaced by annotations in general, but I have never used them and I don't know whether they can solve my problem.

That's why I'd like to know:

  1. Is there a better alternative to my design (either by using annotations or by another means)?
  2. In case marker interfaces are still a solution in some cases, how can I discriminate when should I use them?

0 Answers0