flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: [RT] From Singletons to Unit-testable code
Date Wed, 08 Feb 2012 14:45:42 GMT

On 2/8/12 1:50 AM, "David Arno" <david@davidarno.org> wrote:

>> From: Alex Harui [mailto:aharui@adobe.com]
>> Sent: 08 February 2012 03:10
>> ... And then there are some old singletons like EffectManager that still
> use
>> static methods, which should be using Singleton instead.
>> And then there is the whole debate about Singletons in general...
> Let's have that debate. Replacing static methods with singletons will not
> improve the testability of the code. If those static methods are
> deterministic and have no side effects, then they are fine as static methods
> (and maybe could be turned into global functions as a minor [though
> controversial] improvement.) Otherwise, they need to go.
I don't fully agree.  I don't see how static methods on a class are
substitutable at runtime without resorting to evil tricks.  Static methods
require hacks for event dispatching and can't implement interfaces.  But for
sure, a bad instance method implementation can also make substitution
> Global state, whether via singletons, service locator patterns or static
> methods, always make testing difficult. If we are serious about making the
> Flex framework unit-testable, then we need to get rid of all of them and
> replace them with dependency injection throughout the framework. Anything
> less will - from a testing point of view - just be fiddling whilst Rome
My simple mind just can't understand why we need a sophisticated multi-step
plan or full dependency injection.  Why can't a simpler substitution pattern
do the job?  

Alex Harui
Flex SDK Team
Adobe Systems, Inc.

View raw message