I’m currently refactoring some ugly code and splitting a large and overcomplicated class A into superclass A with subclasses B and C.
My question is, if I had private variables in the overcomplicated class that are only relevant to subclass B after the split, is there a universally accepted convention for where to declare these?
My options are:
protected variable in superclass A
pro: all variables located in central location
con: some variables in superclass unused by all subclasses
private variable in subclass B
pro: only shared variables present in superclass A (more "proper"?)
con: more complicated code management
Thanks for your time!
If they are only relevant to class B, put them in class B. To do anything else, detracts from the readability of the code and will cause confusion in the future.
If you would like to justify your answer to someone, you can point to Separation of Concerns (SoC), which addresses your breaking apart classes.