Design Patterns / Week 7

Multiple LNFSupporting Multiple Look & Feels (LNF)

Designing Graphical User Interface (GUI) started last week. After seeing how Decorator pattern helps us to enrich objects’ functionalities without class proliferation, we’ll investigate this week how can we support different LNF in the same platform. As said in the previous post, there are many GUI frameworks (Java Swing, Qt, .NET Framework etc), each of them employing a specific look of graphical controls (windows, buttons, text areas etc) and a different way of interacting with this controls from keyboard, mouse or other input devices, i.e. a different feel. For example, a button looks different on Windows XP, Mac OS X, KDE or Android: different font for its label, different background color, different border style. User interaction with menus is also different on these GUI frameworks, different feel.

Is it possible to design a GUI framework that supports all these LNF, and others to come? It turns out that the top-level abstractization for this purpose is not that complicated. The main idea is simple: encapsulate the behavior for each LNF in its own set of classes (family) and decide what family of objects to instantiate using Abstract Factory pattern. Other creational patterns will also help here:

More details about supporting multiple LNF and creational patterns are available in this week’s lecture handouts.

Willing to quickly and easily create fancy looking UML diagrams? Try YUML.

This entry was posted in Design Patterns and tagged , , , , . Bookmark the permalink.