A
A
asker2018-10-27 15:50:35
JavaScript
asker, 2018-10-27 15:50:35

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

3 answer(s)
H
Hungry, 2018-10-27
@bybyby

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.

R
Roger2, 2018-10-27
@Roger2

The methods that both need are already like a class like Utils or business logic. Take the general to the third grade.

S
Sasha, 2018-10-27
@aryutin

If there are many classes of the same type, it is worth creating a common class from which they will be inherited.
for example
class Button extends HTMLElement {}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question