K
K
Konstantin2021-02-01 16:07:33
JavaScript
Konstantin, 2021-02-01 16:07:33

What pattern to use in Angular?

I have a TreeService that manages a tree. It has a tree initialization method. In which the traversal of the tree is called and the selection of certain values ​​​​according to the given logic. Then the draw method is called.

The problem is that I want to reuse the service, while not using part of the functionality, for example, not calling the above methods at the entry point, but executing my own logic.

At the same time, the current service contains common methods for any tree, mark a leaf, open, close a tree, and so on.

How to deal with this in Angular?
It comes to mind to create an abstract service class:

class abstract TreeCommon {
   // Common methods and abstract methods for overwriing.
}


Then create separate services with their own functionality:

class TreeMap extends TreeCommon {
}

class TreeLayer extends TreeCommon {
}


The second option is to immediately inherit from the current implementation of the service, which is not very good, because I don’t need half of the functionality. Only basic woodworking.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question