In the previous post, while designing our API we stumbled on a flexibility problem.
How do we add common methods to our API builders without compromising on flexibility?
We are going to use C#’s extension methods. Here is how:
Now when a builder needs to support adding a css class to a css enabled component,
it just has to implement the ICustomCssEnabledBuilder interface.
Now our builder can be used like this
The same technique can be used for the events API.
So our TextBoxBuilder is changed to this.
And now it can be used like this.
Awesomeness achieved !!