lundi 29 juin 2020

Several points of objects creation

I'm developing a framework. It has a kind of Launcher class where all needed by the frameworks's core services and other classes are instantiated (first point of objects creation). There's no dependency on concrete implementations anywhere in the core outside Launcher. It's okay.

But also I have such things as plugins (let's assume there's Plugin class which represents a plugin). Of course plugins should have ability to be added without any changes in the core code. Another condition is that I do not know what services (and other things) a plugin's Plugin class needs for work so I cannot inject them (at least I guess so). Therefore a plugin developer needs to instantiate the dependencies in some function like initializePlugin() (which is in the Plugin class) and it makes this function the second+ point of objects creation.

And instantiation code (in the second+ creation point) then depends on concrete implementations of interfaces. But what if I decide to change implementation of services? I would have to change every point of objects creation (what I cannot do because some plugins can be 3rd party software). So how do I organize classes without changing the second+ points of creation in future? Do I have to use DI container?

Aucun commentaire:

Enregistrer un commentaire