In general, I do something like this, I think how to make it so that you can refer to an existing object.

export class Hand { private render:Render; constructor(render:Render){ this.render = render; } public view(){ this.render.test(); } } export class Render { private hand:Hand; public method(){ this.hand = new Hand(this); } public test(){ } } let render = new Render(); 

It can put the variable render and others into some kind of an array or object and drag from it and add new ones created to it.

And what if in the Hand suddenly need to refer to another object that I might create in the process. How to delegate the object?

Found something here https://github.com/asvetliakov/Huject but something is difficult to understand, you need to understand

Here's another https://github.com/pleerock/typedi is more understandable

  • And what exactly does not suit the existing approach? - Dmitriy Simushev
  • @DmitriySimushev in principle, and so you can live, but the more connections the more difficult the designer or the more methods that are needed just to drop the link to the object. - Serge Esmanovich
  • @DmitriySimushev For example, in Hand I will create a Card object and in it I will create a Cat object and in Cat I will need a Render, I will have to link the link through all the classes - Serge Esmanovich
  • If you properly encapsulate class duties, you don’t have to prokipydik something very deep. I will try to write a detailed answer in the near future (if no one gets ahead). - Dmitriy Simushev
  • @DmitriySimushev will be grateful, in Symfony, for example, in the controller, through this-> get ('name service') you can turn to any previously created service, I would like to do something like that - Serge Esmanovich

0