You need to sign in to do that
Don't have an account?
Updating interface class in managed package
We have a managed package that contains a few global interface classes. These classes are extended within the package but can also be extended after installation in the target org.
These interfaces are chained.
Interface D extends interface C extends interface B extends interface A, which is the base Interface.
And Class D implements interface D
Class C implements interface C
And so on, you get the picture...
All interface classes are used as implementations.
But now we want to add methods to one of the interfaces, let's say B in our example.
This is not possible since we can't add new methods to an interface class. But we need ot inject some methods here for new funcionality.
What would be the best way to go about this? We can't just add them to Class B because we cast the class instances as an instance of the interfaces and then we get an error that object of type interface B doesn't have the method we just added, which makes sense since it's not added to the interface class itself...
However, one way to work around this limitation is to define a new interface that extends the existing interface, and add the new methods to the new interface.
For example, in your case, you could define a new interface B2 that extends B, and add the new methods to B2. Then, any classes that need to use the new methods would implement both B and B2.
Here's an example of how you could define the new interface and update your classes:
Here's an example of how you could define the new interface and update your classes:
In this example, B2 extends B and adds a new method newMethod(). The D and C classes are updated to implement both B and B2, while the B and A classes remain unchanged.
This approach allows you to add new functionality without modifying the existing interfaces or classes, and without breaking any existing code that relies on those interfaces.
If you find this answer helpful,Please mark it as the best answer