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
24
votes
4 answers

Examples of Delegates in Swift

I have been trying to learn how delegation with protocols work. I understood everything, but I can't think of when to use delegation other than when using table views and possibly scroll views. In general, when is delegation used?
Nikhil Sridhar
  • 1,410
  • 5
  • 16
  • 33
23
votes
8 answers

Long delegation chains in C++

This is definitely subjective, but I'd like to try to avoid it becoming argumentative. I think it could be an interesting question if people treat it appropriately. In my several recent projects I used to implement architectures where long…
Sergey K.
  • 23,426
  • 13
  • 95
  • 167
22
votes
4 answers

Difference between Strategy pattern and Delegation pattern

What is the difference between Strategy pattern and Delegation pattern (not delegates)?
hIpPy
  • 3,702
  • 5
  • 41
  • 57
19
votes
2 answers

Javascript event delegation, handling parents of clicked elements?

http://jsfiddle.net/walkerneo/QqkkA/ I've seen many questions here either asking about or being answered with event delegation in javascript, but I've yet to see, however, how to use event delegation for elements that aren't going to be the targets…
mowwwalker
  • 14,309
  • 23
  • 87
  • 144
19
votes
3 answers

Composition vs. Delegation

Is there any difference in terms of implementation as how a composition design can be different from delegation. For example the code below seems to be doing delegation since the user cannot access the composed object (i.e "a") without using b.…
Frank Q.
  • 4,341
  • 9
  • 40
  • 56
18
votes
2 answers

Delegating constructors in c++ () or {}

I read this link of Stroustrup with the following code: class X { int a; public: X(int x) { if (0(s)} { } // ... …
Govan
  • 1,769
  • 2
  • 24
  • 45
16
votes
1 answer

Why only interfaces can be delegated to in kotlin?

I have seen few similar questions, but none had explained why delegation is limited to interfaces? Most of the time in practice we have something that has actually no interface at all, it is a class that implements nothing but provides some…
vach
  • 8,422
  • 8
  • 51
  • 83
16
votes
2 answers

DelegateClass vs Class Inheritance in Ruby

Can someone please provide some insight as to when to use delegation via DelegateClass (e.g. Seller < DelegateClass(Person)) and when to use class inheritance (e.g. Seller < Person) in ruby? class Seller < DelegateClass(Person) def sales …
Kyle Decot
  • 19,418
  • 35
  • 132
  • 245
15
votes
2 answers

ASP.Net web application trying to use Impersonation and Delegation to connect to SQL Server

I'm trying to use Impersonation and Delegation in an intranet ASP.Net web-app in order to pass authenticated users' credentials onto a SQL Server. The web server and SQL server are two separate machines, but in the same domain, so Delegation is…
Graham Clark
  • 12,614
  • 8
  • 46
  • 78
15
votes
1 answer

Delegating constructors: an initializer for a delegating constructor must appear alone

I have a pair of constructors that work just fine in C++03 style. One of the constructors calls a superclass (or base class) constructor ... class Window : public Rectangle { public: Window() : win(new RawWindow(*this)) { refresh();…
learnvst
  • 13,927
  • 13
  • 65
  • 108
14
votes
2 answers

Can I use OpenID delegation with a standard Google account?

I'm currently using ClaimID and have the following data on my website to allow delegation: Are there…
Tom Robinson
  • 7,700
  • 8
  • 55
  • 91
14
votes
1 answer

Difference between @Delegate and @Mixin AST transformations in Groovy

What's the difference between @Delegate and @Mixin AST transformations in Groovy. Maybe my question has to do with OO and when apply different patterns, but I use both and I can achieve the same behavior. class Person { String name = "Clark" …
14
votes
1 answer

C++ question: feature similar to Obj-C protocols?

I'm used to using Objective-C protocols in my code; they're incredible for a lot of things. However, in C++ I'm not sure how to accomplish the same thing. Here's an example: Table view, which has a function setDelegate(Protocol *delegate) …
Justin Mrkva
  • 3,239
  • 4
  • 33
  • 54
14
votes
3 answers

Objective-c asynchronous communication: target/action or delegation pattern?

I'm dealing with some asynchronous communication situations (Event-driven XML parsing, NSURLConnection response processing, etc.). I'll try to briefly explain my problem: In my current scenario, there is a service provider (that can talk to a xml…
Lio
  • 3,982
  • 4
  • 30
  • 37
14
votes
2 answers

C++ 11 Delegated Constructor Pure Virtual Method & Function Calls -- Dangers?

Not a Duplicate of Invoking virtual function and pure-virtual function from a constructor: Former Question relates to C++ 03, not new Constructor Delegation behavior in C++ 11, and the question does not address the mitigation of undefined behavior…
e.s. kohen
  • 213
  • 1
  • 3
  • 20
1
2
3
47 48