Questions tagged [delegation]

A delegate is a type that references a method

A delegate is a type that references a method. Once a delegate is assigned a method, it behaves exactly like that method. The delegate method can be used like any other method, with parameters and a return value

719 questions
164
votes
6 answers

What is a C++ delegate?

What is the general idea of a delegate in C++? What are they, how are they used and what are they used for? I'd like to first learn about them in a 'black box' way, but a bit of information on the guts of these things would be great too. This is not…
Dollarslice
  • 8,654
  • 20
  • 52
  • 80
159
votes
9 answers

Why aren't superclass __init__ methods automatically invoked?

Why did the Python designers decide that subclasses' __init__() methods don't automatically call the __init__() methods of their superclasses, as in some other languages? Is the Pythonic and recommended idiom really like the following? class…
jrdioko
  • 28,317
  • 26
  • 75
  • 116
136
votes
12 answers

Delegates in swift?

How does one go about making a delegate, i.e. NSUserNotificationCenterDelegate in swift?
user3718173
  • 1,363
  • 2
  • 9
  • 4
85
votes
3 answers

Delegate OpenID to Google (NOT Google Apps)

Is it possible to use my personal website/blog to login to sites that use openid, and delegating to my Google account? OK, I searched this question on SO but no good answer. After spent some time I figured out how to do it. I'm going to answer this…
Rio
  • 1,727
  • 2
  • 22
  • 25
66
votes
4 answers

Implementing multiple interfaces with Java - is there a way to delegate?

I need to create a base class that implements several interfaces with lots of methods, example below. Is there an easier way to delegate these method calls without having to create a horde of duplicate methods? public class MultipleInterfaces…
Chuck Mosher
  • 985
  • 2
  • 8
  • 11
62
votes
5 answers

Distinguishing between delegation, composition and aggregation (Java OO Design)

I am facing a continuing problem distinguishing delegation, composition and aggregation from each other, and identifying the cases where it's the best to use one over the other. I have consulted a Java OO Analysis and Design book, but my confusion…
denchr
  • 3,734
  • 11
  • 44
  • 51
51
votes
6 answers

When to use delegation instead of inheritance?

Could someone please explain when would I want to use delegation instead of inheritance?
Cuga
  • 16,782
  • 29
  • 106
  • 156
50
votes
4 answers

What is the purpose of a delegation pattern?

I was looking through the source to SensorManager in Android and found that when you register a SensorEventListener the SensorManager passes control of the listener to a ListenerDelegate. I only bring this up as an example. I read the Wikipedia…
ahodder
  • 11,060
  • 14
  • 63
  • 109
42
votes
3 answers

What is meant by .delegate=self?

Could anyone explain the meaning of someViewController.delegate = self and self.delegate? Where do they help us?
Rajkanth
34
votes
2 answers

How can a method's Javadoc be copied into other method's Javadoc?

I know that there is @inheritDoc, but it's only for methods which override others. I have several classes with many delegate methods (which do not override others). Can their Javadoc be "inherited" (more exactly: copied)? /** here I need the copy of…
java.is.for.desktop
  • 9,703
  • 10
  • 62
  • 100
31
votes
7 answers

jQuery .on() and .delegate() doesn't work on iPad

If you try this snippet on desktop, everything works. Whenever you try it on iPad, it won't do anything. $('body').on('click', '#click', function() { alert("This alert won't work on iPad"); }); div { font-size: 24px; }
Martin.
  • 10,051
  • 3
  • 35
  • 65
30
votes
5 answers

What is Protocol Oriented Programming in Swift? What added value does it bring?

From Apple's own website: "At the heart of Swift's design are two incredibly powerful ideas: protocol-oriented programming and first class value semantics." Can someone please elaborate what exactly is protocol oriented programming, and what added…
Honey
  • 24,125
  • 14
  • 123
  • 212
29
votes
1 answer

When to use Ruby DelegateClass instead of SimpleDelegator? (DelegateClass method vs. SimpleDelegator class)

Probably i am missing something simple, but i do not understand how to use Ruby's DelegateClass method, i mean when to use it instead of SimpleDelegator class. For example, all of the following seem to work mostly identically: require 'delegate' a…
Alexey
  • 3,241
  • 5
  • 25
  • 40
26
votes
3 answers

In OOP, what is forwarding and how is it different from delegation?

Would someone please explain the difference between forwarding and delegation? They seem similar, but I haven't been able to find a good definition of forwarding, so I'm not sure I really understand.
vette982
  • 4,322
  • 7
  • 32
  • 40
25
votes
2 answers

Difference between Decorator pattern and Delegation pattern

What is the difference between Decorator pattern and Delegation pattern (if there is any) ? I don't want to know just about implementation details but also about use case differencies and subjective point of view how to use them. Decorator…
michal.kreuzman
  • 11,132
  • 8
  • 53
  • 66
1
2 3
47 48