[ fromfile: factory.xml id: componentfactory ]
Now consider two libraries, libdataobjects
and libcustomer
, each with its own (concrete) object factory, as shown in the UML diagram in Figure 16.1.
CustomerFactory
, defined in Example 16.5, extends the functionality of ObjectFactory.
Example 16.5. src/libs/customer/customerfactory.h
[ . . . . ] class CUSTOMER_EXPORT CustomerFactory : public QObject, public ObjectFactory { public: static CustomerFactory* instance(); Customer* newCustomer(QString name, QObject* parent=0); Address* newAddress(QString countryType = "USA", QObject* parent=0); private: CustomerFactory(QObject* parent=0); }; [ . . . . ]
CustomerFactory
inherits the ability to create Address
objects from ObjectFactory.
In addition, it knows how to create Customer
objects.
The base-class newObject()
method is smart enough to handle the classes added by Customer provided they are properly registered in that container.
Example 16.6. src/libs/customer/customerfactory.cpp
[ . . . . ] CustomerFactory::CustomerFactory(QObject* parent) : QObject(parent) { m_knownClasses["Customer"] = Customer::staticMetaObject; m_knownClasses["CustomerList"] = Customer::staticMetaObject; }
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |