Good way of giving a singleton getInstance() method with and without arguments -
i have singleton class has 2 methods getinstance() , getinstance(param1, param2).
getinstance() initializes singleton object default values whereas getinstance(param1, param2) initializes singleton object user defined parameters (param1 , param2).
but problem arises when user first calls getinstance() , getinstance(param1, param2) later or viceversa. same case when getinstance(with params) called twice different arguments. i.e., getinstance(param1, param2) called first , getinstance(param3, param4) next.
in above cases second call ignored because singleton object initialized once , should not changed again. but, user never know , under impression second call got executed .
can suggest best way resolve problem ?
booth methods should return same instance, second 1 sets ivas accordingly. there no need user know this. thais idea singelton. if user need know, return null/nil in error-case. way can tell if second call not possible. still leaves question why user needs know this. perhaps different design strategy better?
Comments
Post a Comment