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

761 questions
27
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
  • 2,079
  • 4
  • 31
  • 53
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,670
  • 5
  • 20
  • 39
24
votes
4 answers

Difference between Strategy pattern and Delegation pattern

What is the difference between Strategy pattern and Delegation pattern (not delegates)?
hIpPy
  • 4,649
  • 6
  • 51
  • 65
23
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.
  • 6,001
  • 11
  • 47
  • 62
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.
  • 24,894
  • 13
  • 106
  • 174
21
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
  • 16,634
  • 25
  • 104
  • 157
21
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
  • 10,571
  • 12
  • 68
  • 106
20
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
  • 20,715
  • 39
  • 142
  • 263
17
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
  • 15,455
  • 16
  • 74
  • 121
16
votes
2 answers

Method delegation in python

I'm writing a small framework for orchestrating AWS clusters and there are some common hierarchical patterns that appear over and over again. One such pattern is gathering a collection of instances into a bigger object and then delegating some…
David K.
  • 6,153
  • 10
  • 47
  • 78
16
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,886
  • 8
  • 50
  • 82
15
votes
2 answers

Partial class delegation in Kotlin

How do I partial delegate methods/fields in Kotlin? To be specific: here I am trying to inherit class User from interface TraitA and implement field marked: Boolean in the wrapper StateA. That would clean up the User implementation, because marked…
voddan
  • 31,956
  • 8
  • 77
  • 87
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
  • 8,348
  • 9
  • 58
  • 102
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" …
Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73
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) …
jstm88
  • 3,335
  • 4
  • 38
  • 55
1
2
3
50 51