Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class FooProvider {
- //V1
- global interface CustomFooProviderV1 {
- string bar();
- }
- public static CustomFooProviderV1 getFooProviderInstance() {
- // Use a CMDT or Custom Setting to get the name of the implementing class
- // Use Type.forName and Type.newInstance() to create instance
- //...
- return (CustomFooProviderV1)fooInstance;
- }
- }
- global class FooProvider {
- //V1
- global interface CustomFooProviderV1 {
- string bar();
- }
- //V2
- global interface CustomFooProviderV2 extends CustomFooProviderV1 {
- string raiseTheBar(int height);
- }
- public static CustomFooProviderV2 getFooProviderInstance() {
- // Use a CMDT or Custom Setting to get the name of the implementing class
- string className = 'localFooProvider';
- // Use Type.forName and Type.newInstance() to create instance
- //...
- Type t = Type.forName(className);
- // Create an instance to confirm the type
- object testInstance = t.newInstance();
- if(testInstance instanceOf CustomFooProviderV2) {
- return testInstance;
- }
- if(testInstance instanceOf CustomFooProviderV1) {
- return testInstance;
- }
- return (CustomFooProviderV1)fooInstance;
- }
- public class FooUpgrader implements CustomFooProviderV2 {
- private CustomFooProviderV1 v1;
- public FooUpgrader(CustomFooProviderV1 v1Param) {
- v1 = v1Param;
- }
- public string bar() {
- return 'foobar';
- }
- public string raiseTheBar(int height) {
- throw new InterfaceVersionException('Method raiseTheBar is not supported with an implementation of the v1 FooProvider interface');
- }
- }
- public class InterfaceVersionException extends Exception {}
- }
Add Comment
Please, Sign In to add comment