lundi 23 octobre 2017

Adapter Pattern with different abilities for each adaptee

I am writing a program that will make use of the adapter pattern for a handful of APIs. The goal is to be able to combine and aggregate data from each API. The problem is, not every API has the same functionality. For example:

API A

  • List all markets
  • List specific market price
  • List orders

API B

  • List specific market price
  • List market 24hr high/low

Notice how API B is able to get the 24hr price highs and lows, but API A cannot. Meanwhile, API A can list all markets available, while API B cannot.

What is the ideal way to approach a scenario like this?

  • I have thought about having a FLAGS enum that lists each API's functionalities, but that feels like a roundabout way of doing things and requires a lot of additional code for checking and whatnot.
  • I have considered separate adapters for each ability that the API can handle, but that could require a great deal of inheritance to the point where each API was using 5+ interfaces for the actions alone.

My goal is to make the program easily extendable to other APIs in the future. If this is my goal, how should I approach this? (I am using C# if that matters)

Aucun commentaire:

Enregistrer un commentaire