An object A instantiates an object B as b = B. B stores a list of values, but also some methods related to the creation and manipulation of such values. The methods of B should be used in A, but only by the object internally, not directly by the user that interacts with A. The values of B, however, should be accessible to the user.
How would I implement this in Python in terms of good design?
2 ideas occur to me but I have no means to judge them.
-
wirte a getter Method for b that returns b.values (I do not like that because then b does no longer return the construction signature or alike)
-
store B in a variable _b and then store _b.values in b (I do not like that because it is kind of redundancy)
Are there better or more common solutions that I had not think of? Letting the user use b.values is no option because from the perspective of the user b is just data and he/she should not be confronted with the complexity of B.
Aucun commentaire:
Enregistrer un commentaire