Questions tagged [delegates]

Delegates can refer to several concepts. An object can rely on another (a delegate) to perform a function. Delegation can also refer to programming language feature making use of the method lookup rules for dispatching self-calls. In C#, a delegate defines which method to call when an event is triggered.

Filter by
Sorted by
Tagged with
3
votes
2answers
59 views

Validating CSV headers against an expected list

My application (legacy code) reads a CSV input file with an expected format with regards to Column names as follows: 1st column - Should say "Marker" 2nd column - Should say "Category" 3rd column ... ...
2
votes
0answers
33 views

Inherited class calls initialization code in base class [closed]

I am interested in hearing your opinion on the approach I have taken to have inherited classes initialize their base class. Here's a Machines collection class from that maintains a list of Machine ...
1
vote
1answer
76 views

Repeatedly open and close a PDF document to perform various operations [closed]

I am trying to implement the Execute Around pattern described in Kent Beck's Smalltalk Best Practice Patterns. An example in Java could be found here. Basically, I am repeatedly opening and closing ...
5
votes
3answers
6k views

Measuring method execution time

I want to easily measure method's execution time. Of course instead of doing something like this: ...
3
votes
0answers
152 views

Java - propagating a threadlocal by wrapping a runnable

My aim is to use a thread pool together with a thread local. I cannot use InheritableThreadLocal because the thread data is different per user and there a couple of ...
5
votes
3answers
3k views

Several approaches to a logging class

I'm making a personal logger and so far I have come up with 3 solutions. I have them simplified in this example to highlight my dilemma. I want to know the pros and cons of my approaches and ways to ...
2
votes
2answers
79 views

Counting quiz for children

I made a game for children. This game tests the ability to count (i.e. compare numbers based on magnitude). First you must select the age of the child in the upper menu, then you need to select blocks ...
1
vote
2answers
100 views

Selecting multiple filters based on the true/false conditions

I wrote a method to select the filters (two or more) based on the true/false conditions. Here is the method I used for selecting the multiple filters: ...
6
votes
2answers
434 views

Shopping cart using events and delegates

I am trying to learn events and delegates in C#. To do that I am trying to create a hypothetical console project where when some user submits the orders in his/her shopping cart, I need the Billing ...
1
vote
2answers
94 views

View controllers and delegation for a weightlifting app in Swift

I've got several UIViewControllers that are trying to do too much so I'm trying to learn how to clean them up so that they only have code that does UI things (...
2
votes
1answer
183 views

Amplitude and Frequencies of sound Analyser

As I'm beginner with mobile/OO programming, I reached a situation that confused me and made me wonder if I was coding correctly... The main class: ...
1
vote
2answers
496 views

Setting the path to toolbarAssociatedXibName, with fallback

I have some code that I've included in a project I want to release. Here is one such block: ...
3
votes
1answer
919 views

Event delegation without jQuery

I created event delegation like concept which is present in jQuery. AFAIK, event delegation is used to register an event for an element which is supposed to be added dynamically. So, in jQuery we do ...
7
votes
1answer
676 views

iOS delegation design pattern

I am working on a project that has a Model-View-Presenter structure and use the delegation design pattern that has the following structure/implementation. I would love feedback. The ViewController ...
6
votes
2answers
1k views

Type-Safe Event System

I have recently started writing C# from a strong JavaScript background, and found myself wanting to do something I do all the time in JavaScript: events. Since I have a type system at my disposal, I ...
5
votes
1answer
4k views

Unit test if an event has been raised or not

Given the following event dispatcher code ...
3
votes
1answer
5k views

Removing all delegates from an event dispatcher

Given a class which is an event dispatcher whose underlying store is a dictionary of events whose key is the event type ...
2
votes
1answer
89 views

Writing strings to the screen over time

The following methods just write strings to the screen over time to make it look like a typing effect, instead of all at once. The only difference is the argument in the ...
9
votes
3answers
3k views

A custom Undo Manager

I am working on building an UndoManager in C#. The concept is to store events and property changes in a ...
3
votes
1answer
402 views

Anything I'm missing on this delegate implementation?

Just as the question states and to be sure, am I missing anything on this? Something important/obvious that I overlooked? As is, I can save any functor, function pointer and member function pointer ...
1
vote
1answer
3k views

Using delegates to communicate between forms and networkcommunicator class

I have multiple forms, each of which would like to send message through the network, using my NetworkCommunicator class's ...
5
votes
1answer
175 views

Simulate a person who is working in a quarry with classes

I build my first "bigger" program with classes. Does this look good? Or do you see something, which I could do better? Do you think I could use a delegate for changing the stones to money here? And ...
7
votes
1answer
83 views

Using delegates to avoid duplicate creation of resources

I'm writing a PCL that uses an HttpClient to go visit a few sites and extract data from them. My initial code looked like this: ...
6
votes
1answer
1k views

Retry logic for delegates

I created this class which supposed to take a method and try to execute it. If it fails lets say 10 times, it will throw the original exception thrown by the delegate. Do you have any ideas for ...
3
votes
1answer
94 views

Managing a wish list from an API

I have a class that I use to manage a list to/from an API in Swift. Using a clean code approach, I'm wondering if, how, and why I should change it when I have a class that uses it for just one or two ...
6
votes
1answer
2k views

Generic method for database calls

Background Breaking from MVC, I've implemented the following architecture: POST/GET ➤ PHP ➤ Database Calls ➤ XML ➤ XSLT ➤ HTML All database interactions are ...
3
votes
1answer
742 views

Cancelable thread worker

My goal was to create class, that can run external method in non blocking manner. Second requirement was to be able to abort method run if it is needed (i.e. running user script). I decided to do that ...
5
votes
1answer
709 views

Financial app for retrieving data over a set of dates

I'm writing a financial app that has to get data over a set of dates. The user specifies the start date, end date, and frequency from a list of choices. (daily, weekly, monthly, quarterly, semi, ...
6
votes
2answers
408 views

Is my Delegate defined the right way and does it need to transform to a pretty Event butterfly?

I have read so many bed time stories and ins and outs of how delegates work and why events are to be replaced with delegates (surely not all the time) and just couldn't get my head around it. I am ...
38
votes
2answers
4k views

Wait, is this… LINQ?

Context I'm working on a little project that consists in a series of Microsoft Excel add-ins (.xlam). The code being submitted for review here, is located in the ...
4
votes
1answer
1k views

Asynchronous API calls with delegates and event handlers

I'm making a WindowsPhone 8 app in C#. With this an API so I can convert JSON data into useful objects. I've found a method but am wondering if it is any good at all. The problem is it's been a while ...
3
votes
1answer
2k views

Invoking only the last registered event handler

We are building a game and we have a dialog system. Dialogs may open and stack on top of one another. When every dialog opens, it registers itself to handle the BackButtonPressed event: ...
6
votes
2answers
306 views

C# program that uses events

I am trying to learn C#. Please tell me if the following code respects coding standards and naming conventions because I want to write beautiful code. The purpose of this program was to help me ...
4
votes
1answer
343 views

Stop Watch Application 2.1

After the tips from my previous review. I have come up with these changes: Separation of Concerns Use Delegates I'm asking you guys if this looks good. Other then separate out the ...
3
votes
1answer
167 views

Mixing Watir::Browser into RSpec

In my previous Watir question I was making a module with session_FF accepting a block. Now I want to make the same but via RSpec. Here is my try: ...
10
votes
2answers
825 views

Generating and calling code on the fly

Delegate This class module defines what I'm calling, in this context, a Delegate - here a function that can take a number of parameters, evaluate a result, and ...
4
votes
3answers
416 views

Command-line program for applying several operations on a PDF file

I am building a command-line .exe that can apply several operations on a PDF file (add text, images, resize, crop, etc). Currently, my Program.cs looks a bit like this (it uses CommandLineParser): <...
5
votes
2answers
3k views

Lock-free multiple producer single consumer message queue

For a while now I've been after a lock-free, simple and scalable implementation of a multiple producer, single consumer queue for delegates in C#. I think I finally have it. I've run basic tests on it ...
3
votes
1answer
25k views

Sending a HttpRequest Message, and retrying in case of unauthorised

This code simply sends a HttpRequest message and, if it comes back Unauthorized, gets a new login and tries again. This code is meant to deal with the moment a ...
2
votes
2answers
750 views

Implementation of delegates for flight operations

I borrowed the code from this question. I'm trying to implement the delegate in that code. Below is my outcome so far. What else can be done to improve this code? Any suggestions? I would appreciate ...
5
votes
1answer
3k views

.NET WCF Activator for sync and async calls

I decided to re-write my code responsible for WCF calls, as all of my methods had try-catch-...
8
votes
2answers
11k views

Is this a correct use of using protocols and delegate pattern in Swift?

I am trying to grasp the concept of delegates and protocols in Swift. So I have implemented my own PlayableMedia protocol with two concrete classes ...
3
votes
3answers
3k views

Test questions - Number Generator, Linq, Delegates, Sequences

I have recently been asked to do a test prior to an interview to test my C# skills. I am fairly new to C# (6 months) and I think this showed with me producing an overly complex answer to their ...
8
votes
1answer
383 views

Delegate and Observer pattern implementation for an embedded system - copy and assignment operations

This is a follow-up to this question, which resulted in major confusion on my side regarding forwarding of arguments. Advice regarding that should probably be given in my question on SO. Overview ...
5
votes
2answers
2k views

Delegate and Observer pattern implementation for an embedded system

I'm writing a set of simple widgets for a microcontroller application. I'd like to use the observer pattern to pass around events: when a button is clicked, when a timeout occurs - there are many uses ...
4
votes
4answers
2k views

Thread-safety and delegates with generated numbers

In the main class, loops generate numbers (0~100), and when its generated number is > 20, its value is passed to the thread where it simulates some work with this number. Meanwhile, while this number ...
4
votes
1answer
309 views

State Machine for Character

I come today with a state machine I'm currently working on. Problem: Given any State that the Character is in, a button press or combination of button presses can modify that state in a different ...
7
votes
2answers
2k views

Game passive skill system

I'm trying to create some easily accessible database of different skills. General idea is that every skill should do something different and be able to act on different things (ex. one skill which ...
2
votes
1answer
3k views

Delegate that selects a writable property on a generic

In the following contrived example, I have a collection of PropertyManagers that each contains selector and assigner delegates to read from and write to a property ...
3
votes
2answers
114 views

follow-up review of a custom Undo Manager

This is a follow up review of question 'a custom Undo Manager'. After reviewing all the comments and answers, my code has been revised (completely rewritten) based on the review. Summary The ...