Using services that extract data from web pages as an example (for instance Mercury https://mercury.postlight.com/web-parser/ or Diffobt https://www.diffbot.com/products/automatic/#article) I want to ask a question about how to construct the interfaces and class implementations for a dependency injection (DI)/inversion of control (IoC) scenario.
I'm trying to determine how to best create an IPageExtractor
interface and the subsequent concrete implementations MercuryPageExtractor
and DiffbotPageExtractor
that implement the IPageExtractor
interface given that the actual implementations are quite different.
Obviously this is the entire point of implementing an interface in the first place but I'm having a mental block I need help getting past.
For instance, Mercury uses a key and secret for authentication whereas Diffbot uses a token only. Ok maybe this isn't so different but where I get confused is I have to accommodate this in the interface and of course interfaces are lowest common denominator. Would I for example pass in a collection of auth data and let the concrete implementations sort it out?
Another different is that Mercury returns 3 pieces of data about a web page whereas Diffbot returns like 20 (this may not be technically accurate but the example of possible differences is what I'm getting at). How would I design the interface and concrete implementations to handle this?
A final significant difference is what constitutes success and failure is very different in each case and the message types (format, structure, content) returned for success or failure vary widely as well.
Can you please help think about this problem?
I'm working in C#/.NET but thinking about this in a language-independent way.