mrme44 / LIO

A lightweight image optimizer
MIT License
2 stars 0 forks source link

Create singletons #33

Closed mrme44 closed 9 years ago

mrme44 commented 9 years ago

Make the Pics, UI, and operations objects, singletons.

mrme44 commented 9 years ago

The UI object and perhaps the canvas object also need to be a singletons. The canvas object can always be changed later if there is a need to have two canvases.

mrme44 commented 9 years ago

The operations object needs to be a singleton as well.

mrme44 commented 9 years ago

I figured out a good way of creating singletons for classes who's constructors don't take any arguments; the Pics and Operations classes fall into this category. The UI does not, but it will after issue #34 is resolved.

In the future, https://gist.github.com/SanderLi/e4a89de3ae347b1d4d76 looks like a good way of creating singleton objects whose constructor takes in arguments. However, unlike my solution, this one is possible to get around. I haven't tested it, but it looks as if one might be able to get around the singleton object by doing new Singleton(singletonEnforcer). Because the Singleton class is in a different module, one could only access singletonEnforcer by injecting a function into the Singleton class.

mrme44 commented 9 years ago

Singletons can now be created for constructors as well. There is a way of getting around my "pseudo singletons", but one could only do so knowing they're doing something they shouldn't be.

Singletons can now be created by calling makeSingleton(this) anywhere in the constructor.