Using a static variable will have the same effect as using a singleton!
Imagine if you had two instances of ProductsCache
:
var a: ProductsCache = new ProductsCache();
var b: ProductsCache = new ProductsCache();
a.products = someArrayCollection;
b.products = anotherArrayCollection;
Now, because it's using a static variable, a.products
will be anotherArrayCollection
.
###"Do I really need to learn factories and dependency injections?"
"Do I really need to learn factories and dependency injections?"
Yes, please, learn Dependency injection! You won't regret it! I don't think for this particular case you need a Factory pattern, but it never hurts to learn that too.
Dependency Injection is not that hard actually, the golden rule is: Whenever an object needs your ProductsCache
, give them a reference to your ProductsCache
. Don't use something like ProductsCache.instance.products
. Tell objects about the ProductsCache you want them to use, don't let them ask a singleton about it. Very easy rule to remember: Tell, don't ask.
Using a static variable will have the same effect as using a singleton!
Imagine if you had two instances of ProductsCache
:
var a: ProductsCache = new ProductsCache();
var b: ProductsCache = new ProductsCache();
a.products = someArrayCollection;
b.products = anotherArrayCollection;
Now, because it's using a static variable, a.products
will be anotherArrayCollection
.
###"Do I really need to learn factories and dependency injections?"
Yes, please, learn Dependency injection! You won't regret it! I don't think for this particular case you need a Factory pattern, but it never hurts to learn that too.
Dependency Injection is not that hard actually, the golden rule is: Whenever an object needs your ProductsCache
, give them a reference to your ProductsCache
. Don't use something like ProductsCache.instance.products
. Tell objects about the ProductsCache you want them to use, don't let them ask a singleton about it. Very easy rule to remember: Tell, don't ask.
Using a static variable will have the same effect as using a singleton!
Imagine if you had two instances of ProductsCache
:
var a: ProductsCache = new ProductsCache();
var b: ProductsCache = new ProductsCache();
a.products = someArrayCollection;
b.products = anotherArrayCollection;
Now, because it's using a static variable, a.products
will be anotherArrayCollection
.
"Do I really need to learn factories and dependency injections?"
Yes, please, learn Dependency injection! You won't regret it! I don't think for this particular case you need a Factory pattern, but it never hurts to learn that too.
Dependency Injection is not that hard actually, the golden rule is: Whenever an object needs your ProductsCache
, give them a reference to your ProductsCache
. Don't use something like ProductsCache.instance.products
. Tell objects about the ProductsCache you want them to use, don't let them ask a singleton about it. Very easy rule to remember: Tell, don't ask.
Using a static variable will have the same effect as using a singleton!
Imagine if you had two instances of ProductsCache
:
var a: ProductsCache = new ProductsCache();
var b: ProductsCache = new ProductsCache();
a.products = someArrayCollection;
b.products = anotherArrayCollection;
Now, because it's using a static variable, a.products
will be anotherArrayCollection
.
###"Do I really need to learn factories and dependency injections?"
Yes, please, learn Dependency injection! You won't regret it! I don't think for this particular case you need a Factory pattern, but it never hurts to learn that too.
Dependency Injection is not that hard actually, the golden rule is: Whenever an object needs your ProductsCache
, give them a reference to your ProductsCache
. Don't use something like ProductsCache.instance.products
. Tell objects about the ProductsCache you want them to use, don't let them ask a singleton about it. Very easy rule to remember: Tell, don't ask.