Need advice on OOP.
There is a main class in which a lot of code has accumulated, I want to unload it, that is, if possible, break it into separate classes.
Suppose I have a logical piece, which I carry into a separate class, but quite often the members of the main class are used in it. And there is the problem of choosing the method of access to these members. For the decision I consider such options:
- in add. class, create used variables, and initialize some of them in the constructor, transfer some of them to the required method with arguments
(what problem I see) repeated code, large list of arguments (constructor / method)
- in the constructor add. class to declare the type parameter of the parent class, and when creating the add object. pass the class to the
thisconstructor ( that is, we will receive a link to the parent ) and use the parent link to use the required fields
(what problem I see) As far as I know, it is considered a bad practice to transfer the reference to the parent to the objects. The instance does not need to know what is happening up the hierarchy, the manipulations go only down the hierarchy. Right?
Not an option to leave this piece of code in place.
It will work this way and that, but how to do better? I need the best practices.