samedi 14 mars 2015

How to abstract the idea of themeable components?

I'd like to make certain components of my program themeable by the user such that they can edit values in a settings user interface, such as background color, stroke, or size, and those changes will be reflected once they use that component in the software.


The solution would be simple if the values being changed were always the same, but they are not, as different components may have different "themeable" properties.


I would like to abstract this solution so that a themeable component can either extend a parent Component class who will have the property changing functionality.


My current idea is to create an abstract property class with an update method that returns a boolean and takes a String. For example, if someone was themeing a button, it may have a border property. The update method is defined such that it knows how to update the border based on a String, and the user would be interacting with a UI that knows what Strings to provide based on user input.



public abstract class XProperty
{
public abstract boolean update(String info);
}


I'm sure there is a better or more simple way of doing this. What is the best way to design this functionality?


Aucun commentaire:

Enregistrer un commentaire