Answer the question
In order to leave comments, you need to log in
What is the best way to break a class into modules?
There is a main class A, which contains all the code.
I want to split the program into modules. For example, move a separate ui to class B. An instance of this class creates a new markup and returns it, but class B requires parameters from class A and some methods. I pass the necessary parameters in the arguments, but I find it difficult to decide what to do with the methods. Since I will need methods in both classes. I do not want to copy them manually, so as not to contradict the DRY principle.
Options: pass the result of method evaluation from an instance of class A, pass a method from an instance of class A, make B extends A.
How reasonable is it to do extends in this case? Indeed, in class B, I do not need all the properties and methods of the parent object, and class B complements, and does not extend class A.
Answer the question
In order to leave comments, you need to log in
Google the following terms:
SOLID: SRP, LSP, ISP
GRASP: Polymorphism, Information Expert
+ subtype inheritance
I think after that you will be able to answer your own question.
The methods that both need are already like a class like Utils or business logic. Take the general to the third grade.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question