vendredi 11 octobre 2019

Using parent instance in child class

I'm not sure what this pattern is called, but I wanted to understand if that is considered a good/bad practice.

So, I've Base.class that creates a Children.class instance. Now, in Children class I've an async callbacks A, B, C. I've to react on these async callbacks - but all methods that I need to call on these callbacks are in Base.class as it works as main controller and messages other submodule about new changes.

Very often the simple solution here is to create Callbacks A1, B1, C1 in between Base and Children class. What I hate about this scenerio is that I basically have to duplicate all Children async callbacks (A, B, C) to Base and Children callbacks (A1, B1, C1). Can't I just pass Base class instance in Children and use open functions that way avoiding duplicating similar callbacks that basically does not do anything other than transporting data to different place later on?

Is it bad practise or what?

Aucun commentaire:

Enregistrer un commentaire