T - the type of the base-class to be extended (i.e. replaced in all instantiations) by a certain sub-class.public interface ClassExtension<T>
ClassExtension declares that a sub-class must be instantiated instead of a certain base-class.
In order to register a sub-class as replacement for a certain base-class, implementors have to provide a
ClassExtension and register it using the ServiceLoader-mechanism. This means, they must place a file
named co.codewizards.cloudstore.core.objectfactory.ClassExtension into src/main/resources/META-INF/services/
in their extension-project and enlist their ClassExtension-implementation there.
Important: It is recommended not to directly implement this interface, but to sub-class AbstractClassExtension
instead.
Important 2: If a certain base-class should be replaceable using this mechanism, all occurrences
of new MyBaseClass(...) in the entire code-base must be replaced by
createObject(MyBaseClass.class, ...).
Important 3: It is urgently recommended not to use this approach, whenever it is possible to use a better solution,
preferably a well-defined service (=> ServiceLoader). There are situations, though, e.g. data-model-classes
(a.k.a. entities), where services are not possible and ObjectFactoryUtil + ClassExtension is the perfect solution.
| Modifier and Type | Method and Description |
|---|---|
Class<T> |
getBaseClass()
Gets the base-class to be extended by instantiating a sub-class instead.
|
Class<? extends T> |
getExtendingClass()
Gets the sub-class extending the
baseClass to be instantiated whenever
a new instance of the base-class is requested. |
int |
getPriority()
Gets the priority of this extension.
|
int getPriority()
If there are multiple ClassExtension-implementations for the same baseClass, the
extension with the highest priority (i.e the greatest number returned here) is chosen.
Class<T> getBaseClass()
null.Class<? extends T> getExtendingClass()
baseClass to be instantiated whenever
a new instance of the base-class is requested.baseClass. Never null.Copyright © 2013–2019. All rights reserved.