How to find a girl or dependency injection pattern in action. Part II
Vasily Pereverzev
Posted on January 7, 2020
Implementation
In the previous part, we introduced the basic concepts of the dependency injection pattern.
Now it is time to make out an example implementation (in this example, I use the Qt / C ++ bundle). Let's imagine a basic simple case.
What can we see here?
Module A
Interface IDummyInterface
Service DummyService that implements interface IDummyInterface
Module B
ServiceInjector - the "dating agency".
Picks up metadata (contacts) of the necessary service from ServiceResolver (agency database) and injects it in the client
ServiceResolver - the database of our "dating agency". Able to register services and submit their metadata (contacts) for subsequent injection
Module C
DummyClient - client that needs the functionality declared in IDummyInterface. At the same time, he doesn't want to know anything about the details of the implementation of DummyService
Step 1
Add to the IDummyInterface interface the ability to represent ourselves through the unique identifier QUuid.
The INJECT macro implementation is a simple setter and getter.
The first parameter is the type of interface.
The second parameter - an alias for the service in the scope of the client, needed for simplify calls of a service.
MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
Music notation and composition software
MuseScore is an open source and free music notation software. For support, contribution, and bug reports visit MuseScore.org. Fork and make pull requests!
Features
WYSIWYG design, notes are entered on a "virtual notepaper"
TrueType font(s) for printing & display allows for high quality scaling to all sizes
Easy & fast note entry
Many editing functions
MusicXML import/export
MIDI (SMF) import/export
MEI import/export
MuseData import
MIDI input for note entry
Integrated sequencer and software synthesizer to play the score