How should I structure object oriented code to enforce standardization among several classes?

45 views Asked by At

I have a relatively complicated application that has several requirements. The current structure of the project works, but as it grows it has become unwieldy and I find myself repeating the same code in places. The project as simplified goes like this:

DataSenders -------> MyApp -------> DataReceivers

I have several different API's online, call them A, B, C, and D that I am writing wrapper classes around to standardize the data they send or receive to my app. The tricky part is, they are not exclusively senders or receivers, and my app needs to be able to do both at the same time.

So for example, A, B, and C are all senders. But B, C, and D are all receivers. If I am receiving data from B, I also need to be able to send data to B at the same time, and to do so concurrently (so threaded in a sense where one thread is pulling data in from B and another thread is sending it to B's API). Right now I have three ideas on how I should structure this to simplify the code structure.

  1. Write a general class for DataSender and DataReceiver, and the methods do different things depending on if I instantiate it with an argument as A, B, C or D. This forces every class to have the same methods, called the same way, and they all return the same thing. The only downside is it makes these classes incredibly long and has lots of if else statements doing different things.
  2. Write a parent class for DataSender and DataReceiver and have A, B, C, and D extend them. This way they inherit methods that will be necessary for all of them but can overwrite the methods specific to their API. This is the way I am doing it right now, but Python inheritance can get strange in my opinion, especially multi-inheritance.
  3. Just write wrapper classes around each one and have class A, B, C, and D. This simplifies code greatly, but I have to enforce what methods they have and the output formats by hand which can also get messy.

Any input on which one of these methods would be good for a project that is planning to expand largely would be greatly appreciated, and I'm happy to provide any more details needed. Also, if there are ways to do this that I have yet to think of, please let me know. I am using Python for this project and deploying it on AWS ECS if it sways anything. Thank you.

0

There are 0 answers