[Qt-interest] Design Patterns
Alan Ezust
alan.ezust at gmail.com
Mon Nov 23 19:11:01 CET 2009
Ross Bencina wrote:
> Qt implements quite a few design patterns:
>
> Abstract Factory:
> QMetaObject::newInstance()
> http://doc.trolltech.com/4.5/qmetaobject.html
>
> Adapter / Proxy:
> QGraphicsProxyWidget (adapts QWidget into a QGraphicsItem)
> http://doc.trolltech.com/4.5/qgraphicsproxywidget.html
>
> Composite:
> QObject / QWidget
> http://doc.trolltech.com/4.5/qobject.html
> http://doc.trolltech.com/4.5/qwidget.html
>
> Facade:
> QListWidget, QTreeWidget, QTableWidget
> http://doc.trolltech.com/4.5/qlistwidget.html
> http://doc.trolltech.com/4.5/qtreewidget.html
> http://doc.trolltech.com/4.5/qtablewidget.html
>
> Chain of Responsibility:
> QWidget and QGraphicsItem event bubbling
>
> Command:
> QUndoCommand
> http://doc.trolltech.com/4.5/qundocommand.html
>
> Interpreter:
> QScriptEngine:
> http://doc.trolltech.com/4.5/qscriptengine.html
>
> Memento:
> QByteArray in QMainWindow::saveState() / restoreState()
>
> Observer:
> Signals & Slots
> Model/View framework
> http://doc.trolltech.com/4.5/model-view-programming.html
>
> Any others in Qt?
>
>
I think the whole point of design patterns is that it is the foundation on
which many of the classes in Qt were built, and if you know what they are
and how to reuse them, that will save you lots of work later.
Your list was great, I have a similar one and I added a couple of yours to
it. But here are some additions :-)
Composite:
QObject, QWidget, QGraphicsItem, QTreeWidgetItem, QDomNode,
QHelpContentItem, QResource
Decorator:
QScrollArea, QTabWidget, and I'm sure many more
Facade:
QFile, QProcess, QThread, QTreeWidget, QSqlDatabase, QString, and many
others
Reflection Pattern:
QMetaObject, QMetaProperty
Iterator Pattern:
iterator, Iterator, and foreach loops
Visitor Pattern
QTeeWidgetItemIterator, QWizard (a visitor for QWizardPages)
Singleton:
QApplication, QPluginLoader::staticInstances()]
Monostate:
QSettings
Factory Method:
QFileIconProvider QDomDocument::createElement()
Abstract Factory:
QMetaObject::newInstance(), QImageIOPlugin, QItemEditorFactory,
QAbstractExtensionFactory
Mediator:
QAbstractItemDelegate
> If you're looking for another enlightening read try Martin Fowler's
> "Refactoring" -- another Addison Wesley book which changed my life.
>
> I agree with that, Refactoring is excellent.
Another good book (shameless plug) is called Introduction to Design Patterns
in C++ and Qt4.
http://www.amazon.com/gp/product/0131879057/sr=8-2/qid=1149695799/ref=pd_bbs_2/103-4972622-0091013?_encoding=UTF8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/1905aff3/attachment.html
More information about the Qt-interest-old
mailing list