ios - Design patterns: exposing notifications using a protocol -
i have got several types of logic controller class handle communication remote resource. each class uses instance of network controller class deals connection details: connects resource, sends data, receives data. logic controller classes notified of data changes network controller class using notifications. in current solution each logic controller class registers notifications , implements specific functions deal them differently.
however, if want proper code engineering, wonder whether more robust use protocols , delegation.
i wonder if define methods logical controller classes need implement in order receive notification. not sure if makes sense , correct because i not want inheritance here.
any suggestion?
typically have 1 or 2 (explained later) methods per notification. quite simple mapping. reason have 1 notification per "event" , there little reason chance delegation.
but design good. difference between delegation , notifications? (robustness not.)
a delegate single instance customizes behavior of delegating instance. therefore beside usual "inform" methods (
will…
,did…
) can have ability change behavior of delegating, i. e. returningno
"invalid marker" (should…
) or change data set, operation executed on. (sometimes 2nd method event.) obvious in such cases cannot have multiple instances @ time. delegation in competition subclassing , better choice (white boxing vs. black boxing).you can have many notification receivers want to. cannot change behavior of notification sender. therefore better choice, if have several instances needs information event happened.
if understood use case correctly, notifications fitting requirements.
Comments
Post a Comment