I need some help figuring out the right OOP design choice for my python class.
In my example, letters are appended to a string in separate steps. The string is then printed. For this application, it is not really important to the user to get the intermediate results.
So is it better to pass the string to the constructor and then use private methods for the operations and a dothings
method calling them all?
class A:
def __init__(self, string: str()):
self.string = string
def _append_a(self):
self.string += "a"
def _append_b(self):
self.string += "b"
def dothings(self):
_append_a()
_append_b()
def export(self):
print(self.string)
Or is it better to have the string passed to each method?
class AA:
@staticmethod
def append_a(string):
string += "a"
return string
@staticmethod
def append_b(string):
string += "b"
return string
@staticmethod
def export(string):
print(string)
The interface of A
looks a bit cleaner to me, one can just call dothings
and then export.
However, class A
would be a bit of a black box, while with class AA
the user has some more insights to what is happening.
Is there a 'right' choice for this?