We could have a whole discussion about what the recommended Singleton pattern should be. IMO, it should either be a SingletonManager/Locator, or require two classes, a Manager and an Impl. There are some folks from Flex who felt that simple Singletons (a class with static methods) prevented mocking for unit testing and should be avoided.
IMO, Royale's Basic components should not have any simple Singletons. Other component sets are welcome to use them, the emulation component set has to use them to be compatible with Flex. My 2 cents, -Alex On 1/26/19, 8:42 AM, "Harbs" <[email protected]> wrote: OK. I’ll revert that change. I like the idea of private constructors. That does make more sense than making the class abstract. Singletons was one of the areas that I was wondering how we could improve, and this sounds like a great proposal. Thanks, Harbs > On Jan 25, 2019, at 8:17 PM, Josh Tynjala <[email protected]> wrote: > >> I would never occur to me to use abstract for static-method-only classes. In fact, to me, it makes those classes look like base classes that should be subclassed before using. In Java they allow private constructors instead and I believe that is the recommended pattern for static-method-only classes. > > Interesting! I've never thought of using abstract in that way. I agree with your conclusion about classes with only static methods. When I see that a class is abstract, my first thought is that it is meant to be subclassed specifically so that it can be instantiated. I guess you could also make it final, but that's still potentially confusing. > > I was actually considering private constructors as a potential future enhancement. It would allow developers to prevent static-method-only classes from being instantiated, and it would enable a less-hacky way to implement the singleton pattern.
