I've inherited an old piece of software which makes extensive use of Global variables, which is seeing the usual issues associated with them.
A lot of these Globals I've managed to remove through passing them in (via constructor or method) however one variable (ID
) is so ingrained in the application that passing it between objects and methods will become unmaintainable.
To attempt to mitagate this I have replaced ID
with a method that can defensively check / provide ID
wherever needed, as long as this is a singleton (via IOC container) this will work. I am however very concerned this is going to turn into a anti-pattern.
My questions are:
-
Should I attempt to inject my singleton removing the Global nature of ID (pretty unmaintainable)?
-
Should I use the much rejected 'service' pattern with IOC meaning I reference it directly within methods?
-
Is this actually an acceptable time to use singletons?
This is very much a proof-of-concept at this point but I'd much rather do things properly.
Aucun commentaire:
Enregistrer un commentaire