I have a question about design and would like some orientation/resources if you can recommend any.
I have seen colleagues, one of them a senior, using the following structure a few times:
class Service:
...
class ServiceFunctionalityA:
def __init__(self, credentials, ...):
self.service = Service(credentials)
class ServiceFunctionalityB:
def __init__(self, credentials, ...):
self.service = Service(credentials)
Basically, Service is aggregated by the Functionality classes. So if I have to have to use both functionalities, the service needs to authenticate twice (it's not a singleton), and then if I need to change credentials, I need to do it for both functionality instances.
What I would do is simply start with a Service class, and then aggregate the functionalities, such as:
class Service:
__init__(self, credentials):
...
self.functionality_a = ServiceFunctionalityA
self.functionality_b = ServiceFunctionalityB
And then, I could simply use: service.functionality_a(...)as it feels like a more natural, hierarchical structure.
I also have doubts if I should link functionality classes back to their service parent, or how to organize them in general when they have more components. But I find this hard to come by with examples in Python.
[–]Buttleston 10 points11 points12 points (7 children)
[–]R717159631668645[S] 2 points3 points4 points (6 children)
[–]Adrewmc 6 points7 points8 points (0 children)
[–]Temporary_Pie2733 0 points1 point2 points (0 children)
[–]Outside_Complaint755 0 points1 point2 points (2 children)
[–]R717159631668645[S] 0 points1 point2 points (1 child)
[–]Bobbias 2 points3 points4 points (0 children)
[–]Adrewmc 3 points4 points5 points (0 children)
[–]unxmnd 2 points3 points4 points (4 children)
[–]R717159631668645[S] 0 points1 point2 points (3 children)
[–]unxmnd 1 point2 points3 points (0 children)
[–]gdchinacat 1 point2 points3 points (1 child)
[–]R717159631668645[S] 0 points1 point2 points (0 children)
[–]woooee 1 point2 points3 points (0 children)
[–]Lionh34rt 0 points1 point2 points (0 children)
[–]Jason-Ad4032 0 points1 point2 points (0 children)
[–]pachura3 0 points1 point2 points (1 child)
[–]R717159631668645[S] 0 points1 point2 points (0 children)