jeudi 15 avril 2021

What is the best way to pass certain attribute values from one object to another in OOP?

Considering a class A that instantiates from a class B. Class B requires certain values from an instance of class A. What is best-practice, in terms of the SOLID or other design principles, for passing these values from A to B:

  1. by passing the whole instance of A to the constructor of B
  2. by just passing the necessary attribute values from an instance of A to the constructor of B
  3. depends on the situation?

In case of (3), which criteria would favour one or the other solution?

(I do not know if this has an effect on the possible answers, but I am coding in Python)

Aucun commentaire:

Enregistrer un commentaire