, , , , - .
Injection Dependency , , X Y , X , X, , . Y.
Injection Dependency. - .
wahy (, , ) - . , . , . . GUID.
, . ++ ( #) :
std::map<std::string,IInterface> appInterfaces;
appInterfaces["database"] = new OracleDatabaseModule();
appInterfaces["userinterface"] = new VistaStyleUserInterface();
, . , , . .
MyModule::someMethod()
{
IDatabaseInterface *dbInterface = dynamic_cast<IDatabaseInterface *>(appInterfaces["database"]);
dbInterface->executeQuery(...);
}
If you want to change the implementation of the interface in the application, you can simply change the registry entry, for example:
IInterface *iface = appInterfaces["database"];
if (iface) delete iface;
appInterface["database"] = new SqlServerDatabaseInterface();
source
share