Token interface or logical method for determining the capabilities of an object?

I am developing a rather large hierarchy of Java classes, some of which have a specific property that interests me at runtime (the property is definitely applicable only to classes, not to specific instances).

I could create an abstract boolean method isFooBar()that subclasses could implement to indicate whether this property is present:

public abstract class MyBaseClass {
  ...
  public abstract boolean isFooBar();
}

Or, alternatively, I could use the marker interface FooBarPropertyand do a check instanceoffor the interface:

public class MyConcreteClass extends MyBaseClass implements FooBarProperty {
   ...
}

Or I think you could even use the annotation suggested by AmitD:

@FooBarAnnotation
public class MyConcreteClass extends MyBaseClass {
   ...
}

What are the pros and cons of each method and which should usually be preferred?

+5
2

, ( "" - - ), ( ). , , ? , , API, - / ( , ).

EDIT: : "" ( ) "" ( )

+2

. , . , , , .

, , .

+2

All Articles