Questions tagged [delegation]
14 questions
9
votes
1 answer
Delegation pattern in Python: is it unpopular? Is it considered not Pythonic?
As a Ruby/Rails person, I often deal with method delegation. It's often convenient to delegate a method to a composed object or a constant. Ruby even has a def_delegator helper method to easily build delegators and Rails' ActiveSupport improves the…

art-solopov
- 247
- 3
- 7
9
votes
1 answer
Code Design: Delegation of arbitrary functions
On PPCG, we frequently have King of the Hill challenges, which pit different code bots against each other. We don't like limiting these challenges to a single language, so we do cross-platform communication over standard I/O.
My goal is to write a…

Nathan Merrill
- 2,370
- 2
- 15
- 20
7
votes
1 answer
Why are Scala's Either and Option types not interfaces/traits but classes?
I wanted to create a class CompileResult, that can be treated like an Either type but has some additional useful methods. It should be a CompileSuccess or a CompileFailure (which, too, has some extended functionality). However I can't do that…

valenterry
- 2,429
- 16
- 21
6
votes
1 answer
Best practice to authenticate third party to a website?
I've a website built with ASP.NET, and uses Cookie based Forms Authentication to protect it self from unauthorized access.
It also has a REST based API which uses API key based Authentication. (Key is distributed separately).
We've a case where one…

BuddhiP
- 193
- 1
- 4
4
votes
1 answer
Delegate vs Forwarding in Java OOP
I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source:…

nhoxbypass
- 149
- 6
4
votes
1 answer
Extension versus Delegation
I am using Swift and am wondering about the concepts of Extension and Delegation. Recently I found a case where either one of these two concepts could be applied. This reminded of the "composition over inheritance" principle, which teaches that a…

Vince
- 141
- 3
3
votes
2 answers
Alternatives to the delegation pattern allowing blind messages between components
Delegates and delegation exist to enable passing specific messages to an observer, regardless of that observer's type. In a coordinator-type architecture, where coordinators manage and run the flow of an application (instead of say the UI layer, à…

barndog
- 131
- 5
3
votes
1 answer
How to DRY decorator pattern and other delegation in java
I was refactoring some java to use decorators. All of the decorators inherited from a class ThingDecorator, let's say. This consisted entirely of:
SomeType methodName(OtherType otherThing) {
return…

sqykly
- 219
- 1
- 7
3
votes
1 answer
Do conditional delegation or different member types break the Composite pattern?
Here's how I understand the composite pattern:
In the composite pattern, a root object is composed of objects which may be further composed. Moreover, to be considered composite, all those objects expose a common interface.
My question appears…

kdbanman
- 1,447
- 13
- 19
3
votes
1 answer
Language support for (syntactic) delegation in Java
Composition over inheritance is an old trend or even accepted state of the art in object oriented programming. It would be even easier to use in Java, if there were language support for delegation. Our IDEs, like eclipse, allow for easy generation…

Harald
- 181
- 6
3
votes
2 answers
How to use scala case classes when delegation is needed
Let's assume in our application we want to model cars. We also want to model a car repository where we store some registered cars. How should that be modeled in scala?
Here comes my approach: First, I create a case class PlainCar. This is just a car…

valenterry
- 2,429
- 16
- 21
2
votes
2 answers
Delegating work and programming to component interfaces
I have a MessageHandler class which receives and validates messages before determining which components in the architecture they should be delegated to so they can be processed. This involves calling functions with different names and possibly…

ksl
- 121
- 2
0
votes
2 answers
Should an Express error handler be used to send HTTP 4xx responses?
In other words, should the raising of an HTTP 4xx code be considered an error, and should the job of sending an HTTP 4xx code to a client be delegated to an error handler?
Or is it simpler to just send such codes from whichever local code block we…

Asker
- 109
- 5
-1
votes
1 answer
Should we delegate user input sanitization/validation?
Consider this code:
new FrameworkClass( [ 'query' => $_POST[ 'input' ] ] );
FrameworkClass is supposed to do input sanitization and validation. Should we just trust 3rd party code to do it's job?
My argument would be that I would rather have my…

Hans
- 406
- 1
- 3
- 13