Stateless vs. stateful delegates
by, 04-26-2012 at 07:45 PM (902 Views)
Methods which are present at ComponentUI use JComponent object, as a parameter. UI delegate’s stateless implementation is enabled by this convention. Implementation of stateless UI delegate permits one instance of UI delegate, to get used for component class’s instances. This would be reducing no. of objects that get instantiated.
Suck kind of approach is for various simple GUI components. However, in case of more complexed components, it is not considered as “win” as inefficiency is created due to constant state re-calculations which is worst as compared to extra object creation.
A static method is defined by ComponentUI class, to return a delegate instance:
This method’s implementations will be determining that delegate is stateful or stateless. This happens as components which invoke UIManager.getUI() method for creation of UI delegate invokes the CreateUI method internally at delegate class, to obtain instance.Java Code:public static ComponentUI createUI(JComponent c)