- The Book of Dojo
- The Dojo Book, 0.4
- Part 1: "Introduction"
- Part 2: "Out of the Box" Dojo
- Part 3: "The Dojo Programming Model"
- Part 4: "More on Widgets"
- Part 5: "Connecting the pieces"
- Part 6: "Customizing Dojo Builds for Better Performance"
- Part 7: "Utilities"
- Part 8: "Internationalization and Accessiblity"
- Part 9: "Dojo Community"
- Part 10: "Fresh From The Shed" Dojo
- BookWriting
- Glossary
Understanding The Widget Hierarchy
Submitted by bill on Tue, 08/08/2006 - 04:46.
Before you can write your own widget, you should understand how dojo's widgets are organized, both in terms of where files are and how the class hierarchy works.
Renderer Base Classes
The first thing to notice is the following renderer base classes.
Widget
|-- DomWidget
|-- HtmlWidget
|-- SvgWidget
Each widget implementation will extend either HtmlWidget?, SvgWidget?, or VmlWidget?, according to what browser it supports.
Class Hierarchy
For widgets w/only a single implementation (usually "html"), the class hierarchy is pretty simple. For example, there is a dojo.widget.html.Button that extends HtmlWidget.However, widgets w/multiple implementations are more complicated, because there's a base class that defines common functionality and the parameter list for the widget. This effectively leads to multiple-inheritance, since the widget implementation to pull in stuff from both from the renderer base class and the widget base class. For example, dojo.widget.svg.Chart needs to effectively inherit from both SvgWidget and from dojo.widget.Chart.
Technically, multiple implementations are defined using mixins, which are similar (but subtly different) than multiple-inheritance. In the above case, dojo.widget.svg.Chart extends HtmlWidget but mixes in dojo.widget.Chart base class.
Directory Structure
For widgets w/a single implementation, like Button:- src/widget/Button.js - defines dojo.widget.html.Button
- src/widget/Chart.js - defines dojo.widget.Chart base class
- src/widget/svg/Chart.js - dojo.widget.svg.Chart, svg implementation
- src/widget/vml/Chart.js - dojo.widget.vml.Chart, vml implementation
