I have a program that communicates with an API to get information on different organizations, so I have an Organization
class and an ApiCall
class which are both closely related. As the API I'm using requires different tokens, url endpoints and authentifications to be used depending on the organization I'm trying to get data, I use a different instance of ApiCall
for each instance of Organization
(basically a 1-1 relationship).
So the first thing that comes to mind is to have an ApiCall
instance as a property of Organization
, however the api class has several methods that can alter or update data from the Organization
class.
So there are many ways of implementing this. Personally I was considering 4 of them:
- A circular reference, where Organization holds an ApiCall instance as a property and
ApiCall
holds anOrganization
instance - I could have ApiCall as a nested class inside
Organization
, however both classes are fairly sizeable (>300 lines) so I don't like the idea of mixing them. So maybe haveOrganization
as a partial class where one file has theOrganization
methods implementation and the other file has the nested class (ApiCall
) implementation? - Have a static
Dictionary
shared across the program correlating theOrganization
andApiCall
instances - Split
Organization
in 2 classes,OrgData
andOrgActions
, whereOrgActions
referencesApiCall
andOrgData
andApiCall
referencesOrgData
I'm leaning towards alternatives 2 or 4 at the moment, but I was wondering what others would consider the better choice.
new ApiCall(this).DoSomeWork()
? Or does the ApiCall actually retain state/data for a functional purpose?