![]() | Force-FrameworkMark Brennand |
Description | Copyright (c) 2025 Mark Brennand, released under MIT License. Class providing the Apex Type API. An instance of an Apex Type may be constructed by calling the newInstance method. If the newInstance method constructs an implementation of the Factory interface then the newInstance method of the Factory implementation is called to construct the object. This can be used to hide the constructor of the object from the application. For example, say we want to prevent construction of a class by the application. A class can be written that has a private constructor. The Type.newInstance method would be unable to construct an instance of the class. To allow construction, the class would add a public inner class implementing Factory. This method can create an instance the class with the private constructor. To construct the class, call Types.newInstance, passing the inner Factory class as argument. The Factory is intended to be used to prevent the mis-use of an implementation of an interface. The application's only access to the class would be through the interface it implements. The S of SOLID is Single Use Only. The Factory is a way of enforcing this, as the class implementing the interface will only have the use defined by the interface it implements. See README for full details of the Types API. |
---|---|
Author | Mark Brennand |
Description | Creates an object instance for the given type. The type must have a no-op constructor. |
---|---|
Parameter | type: The type for which a new object instance is to be created. |
Returns | The new instance of an object for the given type. Or an exception if an instance could not be constructed. |
Description | Supports use of a factory when instantiating a class. If an instantiated class implements this interface then the newInstance method will create the actual instance. |
---|
Description | Builds a new instance of the class the factory is acting for. This would allow a Factory implementation to return a class which does not have a public constructor. |
---|---|
Returns | The object instance. |