Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:33:45+00:00 2026-05-31T03:33:45+00:00

I’m developing a library in which I have two groups of classes: A) a

  • 0

I’m developing a library in which I have two groups of classes:

A) a couple of classes with a bunch of functions, or “actions”, already written in code

B) a few classes which must be “configured” when instantiated, in a way that the user using my library can instantiate objects from this second group of classes and “assign” actions from the first group

Right now I’m using delegates, like this:

Somwhere in the code I declare some delegates that are used by A and B:

public delegate void Action03(int value);

Then I have the “actions” implemented in the group A:

public Delegates.Action03 DoSomething03 = delegate(int value) { [code to execute when this action is specified on the constructor] };

And finally we use constructors like the following to instantiate objects from group B, where we pass as arguments the delegates/actions that we want:

public SomethingGroupB(Delegates.Action03 act03) { ... }

So of course, we can instantiate objects passing delegates as arguments:

SomethingGroupB somthg1 = new SomethingGroupB(GrpA01.DoSomething03);

But the whole point is that we can instantiate similar objects but assigning different actions:

SomethingGroupB somthg2 = new SomethingGroupB(GrpA07.DoSomething03);
SomethingGroupB somthg3 = new SomethingGroupB(GrpA01.DoSomething01);
SomethingGroupB somthg4 = new SomethingGroupB(GrpA02.DoWhatever);

So… as a summary, I want to have pre-coded (in my library) actions, and the user must choose the actions assigned to a new object when it is instantiated, and those actions don’t change.

I guess I could also do it with events, but I don’t need to add and remove “actions”, they are fixed for the whole life of each object of type B.

So my question is: is there a better, nicer, cleaner solution than this one I’ve implemented with delegates?

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:33:46+00:00Added an answer on May 31, 2026 at 3:33 am

    So my question is: is there a better, nicer, cleaner solution than this one I’ve implemented with delegates?

    The one improvement I would suggest would be to use the delegates defined in the framework, and not define your own. For example, your Action03 delegate is just a System.Action<int>. This would provide a bit more usability in terms of making the API more discoverable.

    That being said, this is effectively using delegates to implement the Strategy pattern. Provided this provides the full functionality you need, it is potentially a good option here, and rather clean.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.