What are the advantages of the delegate pattern over the observer pattern?
In the delegate pattern, only one object can directly listen to another object’s events. In the observer pattern, any number of objects can listen to a particular object’s events. When designing a class that needs to notify other object(s) of events, why would you ever use the delegate pattern over the observer pattern? I see the observer pattern as more flexible. You may only have one observer now, but a future design may require multiple observers.
Template method within one class without subclasses or inheritance
I have an algorithm with mostly invariant parts that needs to be reused within one class so as to stay DRY.
Why use protocol, not call the method directly?
I was asked this question in an interview. For eg: UITableviewDelegate
protocol has CellForRowAtIndexpath
. Why make it a delegate method in a protocol
not a method in the UITableView
class and call it directly?
Do delegates defy OOP
I’m trying to understand OOP so I can write better OOP code and one thing which keeps coming up is this concept of a delegate (using .NET). I could have an object, which is totally self contained (encapsulated); it knows nothing of the outside world… but then I attach a delegate to it.
Do delegates defy OOP
I’m trying to understand OOP so I can write better OOP code and one thing which keeps coming up is this concept of a delegate (using .NET). I could have an object, which is totally self contained (encapsulated); it knows nothing of the outside world… but then I attach a delegate to it.
Why would I ever use delegates if I’m not doing events? [duplicate]
Original close reason(s) were not resolved
Why would I ever use delegates if I’m not doing events? [duplicate]
Original close reason(s) were not resolved
Why would I ever use delegates if I’m not doing events? [duplicate]
Original close reason(s) were not resolved
Why would I ever use delegates if I’m not doing events? [duplicate]
Original close reason(s) were not resolved
Why would I ever use delegates if I’m not doing events? [duplicate]
Original close reason(s) were not resolved