The smaller the interface, the better

It would be better to separate this into two different interfaces, one for each method:

 

With this design, objects that derive from XMLEventParser and implement the from_xml() method will know how to be constructed from an XML, and the same for a JSON file, but most importantly, we maintain the orthogonality of two independent functions, and preserve the flexibility of the system without losing any functionality that can still be achieved by composing new smaller objects.

There is some resemblance to the SRP, but the main difference is that here we are talking about interfaces, so it is an abstract definition of behavior. There is no reason to change because there is nothing there until the interface is actually implemented. However, failure to comply with this principle will create an interface that will be coupled with orthogonal functionality, and this derived class will also fail to comply with the SRP (it will have more than one reason to change).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.35.179