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 8057585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:04:44+00:00 2026-06-05T09:04:44+00:00

I have been looking for a neat answer to this design question with no

  • 0

I have been looking for a neat answer to this design question with no success. I could not find help neither in the “.NET Framework design guidelines” nor in the “C# programing guidelines”.
I basically have to expose a pattern as an API so the users can define and integrate their algorithms into my framework like this:

1)

// This what I provide
public abstract class AbstractDoSomething{
   public abstract SomeThing DoSomething();
}

Users need to implementing this abstract class, they have to implement the DoSomething method (that I can call from within my framework and use it)

2)

I found out that this can also acheived by using delegates:

public sealed class DoSomething{
   public String Id;
   Func<SomeThing> DoSomething;
}

In this case, a user can only use DoSomething class this way:

DoSomething do = new DoSomething()
{
  Id="ThisIsMyID",
  DoSomething = (() => new Something())
}

Question

Which of these two options is best for an easy, usable and most importantly understandable to expose as an API?

EDIT

In case of 1 : The registration is done this way (assuming MyDoSomething extends AbstractDoSomething:

MyFramework.AddDoSomething("DoSomethingIdentifier", new MyDoSomething());

In case of 2 : The registration is done like this:

MyFramework.AddDoSomething(new DoSomething());
  • 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-06-05T09:04:45+00:00Added an answer on June 5, 2026 at 9:04 am

    Which of these two options is best for an easy, usable and most importantly understandable to expose as an API?

    The first is more “traditional” in terms of OOP, and may be more understandable to many developers. It also can have advantages in terms of allowing the user to manage lifetimes of the objects (ie: you can let the class implement IDisposable and dispose of instances on shutdown, etc), as well as being easy to extend in future versions in a way that doesn’t break backwards compatibility, since adding virtual members to the base class won’t break the API. Finally, it can be simpler to use if you want to use something like MEF to compose this automatically, which can simplify/remove the process of “registration” from the user’s standpoint (as they can just create the subclass, and drop it in a folder, and have it discovered/used automatically).

    The second is a more functional approach, and is simpler in many ways. This allows the user to implement your API with far fewer changes to their existing code, as they just need to wrap the necessary calls in a lambda with closures instead of creating a new type.

    That being said, if you’re going to take the approach of using a delegate, I wouldn’t even make the user create a class – just use a method like:

    MyFramework.AddOperation("ThisIsMyID", () => DoFoo());
    

    This makes it a little bit more clear, in my opinion, that you’re adding an operation to the system directly. It also completely eliminates the need for another type in your public API (DoSomething), which again simplifies the API.

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

Sidebar

Related Questions

I have been looking everywhere for this answer. I can't find any solution. I
I have been looking around for an answer to this and have not been
I have just been looking into Linq with ASP.Net. It is very neat indeed.
I have been looking over the web but have not come across an answer
I have been looking around for an answer for a specific question but just
I have been looking at many ASP.Net MVC client side validation ideas including xVal.
I have been looking to implement a custom class of : IList<ArraySegment<byte>> this will
I have been looking at LLVM lately, and I find it to be quite
I have been looking on this site and on other how to set the
I have been looking through some MFC code and i came across this expression.

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.