This interface only exists for documentation of the concept of a
variant. An operation may have a
variant that influences its behavior. This can be anything from a strategy (e.g. "bubble-sort" for a sort
operation) to something that causes additional steps to take place (e.g. "keep-backup" for a save
operation). In general it is recommended by making this explicit by different signatures with reasonable
names. However, sometimes there is need for generic code to call a single operation with different
variants. In such case an additional argument can represent which variant of the operation shall be used.
This can be done in one of the following ways:
- take the variant as
Object for ultimate flexibility and only link to Variant for
documentation.
- take the variant as
Variant to make it more expressive but also more invasive.
- take a specific type (e.g.
Enum or Pojo) as input that may
implement this interface for documentation purpose (but is not required to do so).
In any case you should avoid casting a given
Variant. Instead, whenever possible use a simple type
for
Variant such as an
Enum or
String (from a constant). Then you can do something
like
if (MyVariantEnum.SPECIAL == variant) { doSomethingSpecial(); } ....
ATTENTION:
If not documented otherwise a
Variant may always be
null what is typically the
default.