Search code examples
user-interfaceskinningskin

How to make my applications "skinnable"?


Is there some standard way to make my applications skinnable?

By "skinnable" I mean the ability of the application to support multiple skins.

I am not targeting any particular platform here. Just want to know if there are any general guidelines for making applications skinnable.

It looks like skinning web applications is relatively easy. What about desktop applications?


Solution

  • Skins are just Yet Another Level Of Abstraction (YALOA!).

    If you read up on the MVC design pattern then you'll understand many of the principles needed.

    The presentation layer (or skin) only has to do a few things:

    • Show the interface
    • When certain actions are taken (clicking, entering text in a box, etc) then it triggers actions
    • It has to receive notices from the model and controller when it needs to change

    In a normal program this abstraction is done by having code which connects the text boxes to the methods and objects they are related to, and having code which changes the display based on the program commands.

    If you want to add skinning you need to take that ability and make it so that can be done without compiling the code again.

    Check out, for instance, XUL and see how it's done there. You'll find a lot of skinning projects use XML to describe the various 'faces' of the skin (it playing music, or organizing the library for an MP3 player skin), and then where each control is located and what data and methods it should be attached to in the program.

    It can seem hard until you do it, then you realize it's just like any other level of abstraction you've dealt with before (from a program with gotos, to control structures, to functions, to structures, to classes and objects, to JIT compilers, etc).

    The initial learning curve isn't trivial, but do a few projects and you'll find it's not hard.

    -Adam