K
K
Konstantin2020-02-06 19:39:22
typescript
Konstantin, 2020-02-06 19:39:22

How to correctly describe the button class?

Described the abstract class Button on the basis of which different, specific buttons are generated that perform different functions on click.

In my abstract class, properties are defined that describe the button itself, as well as an abstract click method that returns a promise.

Now, there is a specific "show on map" button class, it has additional dependencies that allow, for example, to send a message on click.

Another button, requires other dependencies.

How to create several different buttons from the same context with this in mind?

It turns out that in the place where the buttons are created, extra dependencies that are needed only by these buttons are imported.

Can this approach be isolated and made more flexible?

The final essence is this, to create several buttons that perform a different function, a callback.

In what context to handle the button click event? In the context of the call or in the button class itself?

How can I dynamically create buttons by sending only the button type as input, like "copyButton"?

Whereas the copyButton requires dependencies on other classes.

A factory that creates specific buttons cannot be implemented, because it is impossible to determine which button object will be created and with what dependencies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-02-06
@Junart1

I didn’t quite understand your task, but read about the Linker pattern .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question