ios - What is this design pattern called where methods are instance methods and not class methods? -


 nsdata *_dataarchive = [[nsuserdefaults standarduserdefaults]                                          objectforkey:@"session"]; 

this style pretty common in obj-c.

why [[nsuserdefaults standarduserdefaults] somemethod]? here somemethod instancemethod?

why not [nsuserdefaults somemethod]? here somemethod class method.

your confusion may believe there can 1 nsuserdefaults. isn't true. original design of nsuserdefaults included ability fetch defaults particular user initwithuser:. never implemented (and deprecated), demonstrates limitation you'd face if it'd been designed class methods.

in latest foundation, there's new initwithsuitename: can used share defaults between related applications. it's nice didn't have limitation, if took decades used.

there's important lesson here designing own apis. in general it's better have accessed instances ("shared...", etc.) rather forcing single instance can never expand on.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -