Object Handler

From MightyWiki

Jump to: navigation, search

Object Handlers are core elements that complement Items properties. They extend items by providing services like loading an item's children, parent, and icon. Object Handler is actually only an interface, and not a standalone class, and therefore is quite flexible in terms of implementation.


Architecture

In principle, the services defined by Object Handlers can be easily implemented by the MBItem super class alone, But a slightly different architecture was chosen, instead of having MBItem implement MBObjectHandler, a MBObjectHandler instance is contained inside each MBItem. Usually subjects of the same type will share a common object handler. If the handler pointer is null, default values will be returned by MBItem.Children and MBItem.Parent etc.

A developer may choose not to use object handlers, and instead override properties like Children/Parent and functions like loadChildren/hasChildren directly by inheriting from MBItem. If you want to delegate these tasks to a different class other than MBItem, use handlers.

Extensions

Object Handlers are one of the ways to extend Mighty Box. Plugins can use object handlers to add children to subjects that mighty have originated from other plugins. for example, iTunes plugin might take the file system iTunes application file item and add children to it (Playlists, Artists, Albums, ...) Another possible use is icon providers - use object handlers capabilities to re-"skin" items icons.