$bookStorage = new BookStorage;$bookStorage->store('Фёдор Михайлович Достоевский', 'Идиот');
$book = new Book;$book->author = 'Фёдор Михайлович Достоевский';$book->title = 'Идиот';$database = new Database;$bookStorage = new BookStorage($database);$bookStorage->store($book);
book::book(string inAuthor, string inTitle, BookStorage * inStore = 0, Database * inBase = 0),author(inAuthor),title(inTitle){store = inStore;base = inBase;}
PHPclass BookStorage{ private $db; public function __construct() { $this->db = new Database; // or //$this->db = Database::getInstance() } public function store(Book $book) { $this->db->insert(book); }}
PHPclass BookStorage{ private $db; public function __construct(Database db) { $this->db = db; } public function store(Book $book) { $this->db->insert(book); }}
PHPclass IStorage { virtual void insert(Book);} class Database: public IStorage { virtual void insert(Book) {...}} class BookStorage{ private $db; public function __construct(IStorage db) { $this->db = db; } public function store(Book $book) { $this->db->insert(book); }}
C++ (Qt)ioc.forClass(IStorage).create(Database);
C++ (Qt)class Database { Database(One a, Two b) { ... } ...} ioc.forClass(IStorage).create(Database);ioc.forClass(One).create(OneStuff);ioc.forClass(Two).create(AnotherStuff);
C++ (Qt)db = ioc.get(IStorage)
C++ (Qt)class Bla { [Inject] public Database storage; ... storage.insert(book);}