While it is not a good idea to keep changing the interface in a project, but when required, we normally create a new interface and new set of classes. I believe at the lower level of implementation, we could use extension methods for the interface.
This ofcourse depends on the context of the change request
Lets take a very simple example. There are many ways to offer extensions. This is one of the many ways, using C# Extension methods.
So,
A class called, Operations implements the above interface.
Now, we want to add a Run/Execute Functionality to ObjectOperations. (If each customer wants a different extension, we would need to think in a different way. It is not good to have too many extension methods. It will become difficult after a point to maintain them.Extension methods operate at the namespace level and have few limitations. Please check the msdn documentation for the same.)
We would either have to create a new interface and implement it in the required classes or just add an extension method to the IObjectOperations interface.
By adding an extension to this interface, all the classes that would implement it would be able to use this extension directly.
Lets try to use it in our Main Program
Run will appear in the intellisense as an extension method.
No comments:
Post a Comment