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
ApiCallholds anOrganizationinstance - 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 haveOrganizationas a partial class where one file has theOrganizationmethods implementation and the other file has the nested class (ApiCall) implementation? - Have a static
Dictionaryshared across the program correlating theOrganizationandApiCallinstances - Split
Organizationin 2 classes,OrgDataandOrgActions, whereOrgActionsreferencesApiCallandOrgDataandApiCallreferencesOrgData
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?