public static interface OD.Binding
A Binding is just a mapping of (type,tags)->supplier. If a (type,tags) is mapped to a non-null supplier, we say this binding applies to (type,tags).
A subclass implements map(ClassType, Object...)
to provide arbitrary binding strategy. For example, a Binding
can choose to apply to all subtypes of `Pet`,
returning a different supplier for each subtype.
A Binding should be stateless and thread-safe.
Abstract Methods | |
---|---|
<T> OD.Supplier<? extends T> |
map(ClassType<T> type,
Object... tags)
Map (type,tags) to a supplier.
|
Set<? extends Class> |
getApplicableClasses()
Get all classes this Binding may apply to.
|
<T> OD.Supplier<? extends T> map(ClassType<T> type, Object... tags)
Return `null` if this Binding is not applicable to a given (type,tags).
This method may be invoked multiple times for the same (type,tags); same or equivalent suppliers should be returned for the same (type,tags).
The returned Supplier will be invoked once by every matching `OD.get()` call.
The returned Supplier may be cached for multiple `OD.get()` calls.
Set<? extends Class> getApplicableClasses()
If this binding applies to a (type,tags),
the class of the type
must be in the returned Set.
It's OK if the Set contains more classes than necessary.
Return `null` to represent the set of all classes, if it's difficult or impossible to enumerate applicable classes.
This information is used for internal optimization; try to be precise and return the smallest set.