Nov-18-2022, 08:53 PM
I need to build a mother-child-like class tree.
Dont know which is the best practice how to structure it.
I could define a top-level class A which has some own attributes and at least 1 sub class B.
The class B itself has again some own attributes and at least 1 sub class C, and so on...
I see 2 ways:
(1)
call instance of Class A, which has a method "fill_own_attributes" and "add subclass(B)".
When the instance of A is called it automatically sets its attributes and adds the subclass B.
When the instance of B is called it automatically sets its attributes and adds the subclass C.
(2)
Having a global builder-function which starts creating a temporary instance of Class C, setting all its attributes.
When all is done, adding this instance as a child to a new instance of Class B, then setting all attributes of B.
When all is done, adding this instance as a child to a new instance of Class A, then setting all attributes of A, which is the highest class. Then its done.
I think first one looks better, but is there any other way? Someone has any info material about my problem?
Dont know which is the best practice how to structure it.
I could define a top-level class A which has some own attributes and at least 1 sub class B.
The class B itself has again some own attributes and at least 1 sub class C, and so on...
I see 2 ways:
(1)
call instance of Class A, which has a method "fill_own_attributes" and "add subclass(B)".
When the instance of A is called it automatically sets its attributes and adds the subclass B.
When the instance of B is called it automatically sets its attributes and adds the subclass C.
(2)
Having a global builder-function which starts creating a temporary instance of Class C, setting all its attributes.
When all is done, adding this instance as a child to a new instance of Class B, then setting all attributes of B.
When all is done, adding this instance as a child to a new instance of Class A, then setting all attributes of A, which is the highest class. Then its done.
I think first one looks better, but is there any other way? Someone has any info material about my problem?