I've started realising the power of multicore but, having used it in anger a couple of times, certain limitations in my approach have come to light.
I know that all my cores will require a stylesheet and a library. My approach thus far has been to load these dependencies in the shell core and pass them to my child cores using the interface method outlined here:
http://www.as3dp.com/2009/07/22/a-non-flex-actionscript-example-of-a-puremvc-multicore-application/There are a few things which I don't like about this approach.
- It's quite a tedious process passing these dependencies through the document class, the facade, the start up command, and finally setting them on the core's Proxy.
- It doesn't feel right accessing the library and stylesheet from a Proxy.
- The method of accessing these dependencies differs between the shell and child cores.
To that end I had decided to handle my library and stylesheets as multitons. It seems to me that this approach would solve the issues outlined above and also make it very easy for me to define a separate library and stylesheet for a particular core should I need to. I already handle my Dictionary and Settings in this way.
My concern is with the (growing) number of dependencies which are accessible as singletons or via static methods. In my case these are:
- Dictionary (multiton)
- Settings (multiton)
- StyleSheet (multiton)
- Library (multiton)
- Logger (static factory)
- LayoutManager (multiton)
Admittedly, the addition of two doesn't make a massive difference to the total, but it has made me think.
I'd be lying if I said that we did much (any) test driven development or unit testing, and it might be that I'm worrying about problems I may never encounter, however I am conscious enough of the negative implications of rampant singleton use to be concerned.
Given that the (house) rule is that these dependencies should only ever be accessed via the static methods within the boundaries of the framework, do you think I'm setting myself up for problems in the future with this approach? Have I got too many singletons? If so, what can I do to improve my approach? I have considered using a ServiceLocator but lack of familiarity with it as a pattern has put me off diving in.