ios - Valid use of singleton, Objective C -
i'm bit noobish design patters. have started use singletons, , thinking of using 1 conveniently store data in centralized location, before doing read few posts seem saying not correct design (or maybe confused), not clear why. want this:
store several arrays of objects in centralized place objects can processed persistence.
if not singleton there better way this? if bad design great know why.
many singleton implementations glorified global variables. while may seem nice , convenient who's not written , maintained lot of code, there many problems using global variables -- such prohibited many experienced developers , teams.
…store several arrays of objects in centralized place objects can processed persistence.
even 1 global variable pain, several arrays of them makes larger problem.
ask yourself: why must these objects in arrays present , reachable part of program? portions of implementation need visible, , portions @ times. why should these arrays of objects allocated , active? create models , pass them instead, , hold them ivars needed.
also, if persisted, needn't loaded because can read/write need when need it.
the use of globals (singleton) going obfuscate object dependency graph (bad -- maintenance nightmare).
there no evidence in op case atypical. although may seem idea now, convenience today costs lot in future.
much has been written misuse of global variables , singletons, , problems introduce (an objc singleton/global not different in regard implementation in e.g. c, c++, or java). articles from, 20 years ago still have advice -- equation more complex today.
Comments
Post a Comment