I think my question will best fit here because it's more architectural then coding.
- IStyleClient (an interface that should enforce the usage of StyleManager).
- StyleManager (a centralized storage for CSS-like styles + an instrument for setting styles on StyleClient[s]).
- A variety of StyleClient (These classes need to be styled).
: I would prefer to make it so that by implementing the interface, the clients would:
- enforce importing StyleManager (this is easy).
- embedding themselves into StyleManager's tree of clients (i.e. styles may be inherited through parent-child chain).
- be notified when their style changes.
- provide API for changing their style whilst notifying StyleManager.
I know this mechanism exists in Flex framework, and I know at an average-good level how it works, but I would like to make it more logical and efficient if possible.
So, I was thinking about something like this:
if I have a method in the IStylable
Assuming the developer would add listener to StyleChangeEvent dispatched from the manager and notify the manager back, when the style is changed, I feel like I'm giving to much freedom to the 3rd-party developer, that may also not know he should do the above...
Another way of doing the same thing is like so:
* @author wvxvw
public interface IStylable extends IEventDispatcher
function get styleName():String;
function get styleID():String;
function get stylableParent():IStylable;
function get stylableChildren():Vector.<IStylable>;
function get style():Object;
* @param parent
* @param theStyle
* @param children
* @return This function will be called on style or property change.
* It must have the following signature:
* <code>function(property:String, oldValue:*, newValue:*):Boolean</code>
* This function should return <code>true</code> if the property change marks
* parent as "dirty" and false otherwise.
function appendToChain(parent:IStylable, theStyle:Object,
I cannot tell it looks any better to me, besides, id doesn't enforce StyleManager import.
I hope I explained it, but, if I didn't... I'll be happy to add more info. And if there is a common way to do such thing, I'd like to read about it, but, I think I just don't know how to call this, so, google / wiki aren't helpfull quite as much this time