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

  • SEARCH
  • Home
  • 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 8076039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:10:45+00:00 2026-06-05T15:10:45+00:00

I have a C# class that has some functionality that I’d like to allow

  • 0

I have a C# class that has some functionality that I’d like to allow a client of the class to override. Specifically I’d like the following:

  1. If the client does nothing, they get our default behavior
  2. The client can override the behavior and cause our default behavior to not be called.
  3. The client can override the behavior and cause our default behavior to be called as a pre/post/middle operation.

My current thinking is to:

  1. Expose an event that the client would subscribe to if they wanted to override the behavior.
  2. Expose a method with the default behavior (that matches the signature of the event):
    void DefaultBehavior()
  3. Whenever we attempt to fire the event, if the delegate is null, we call our default behavior method, otherwise, we call the delegate of the event:

    if (eventDelegate == null)
        DefaultBehavior();
    else
        eventDelegate();
    

When the client overrides the behavior they can optionally call our DefaultBehavior method to get the desired behavior.

Do you think this approach will be intuitive enough from the client’s perspective? Or can you suggest any alternatives that might be better?

  • 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-05T15:10:46+00:00Added an answer on June 5, 2026 at 3:10 pm

    Well, if you want your client to override some behavior, why not create a virtual function, an let the client actually override it?

    It’s the straightforward way of accomplishing this. No need to reinvent the wheel.

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

Sidebar

Related Questions

I have a simple Java class that has some methods: public class Utils {
the basic idea is that you have some class that has a reference type
I have a class that contains data from some model. This class has metadata
I have a rails app that has some simple functionality, allowing the user to
I have a grid on WPF form and another class, that has some events.
I have a class that has an inner struct/class (I have decided which yet,
I have a class that has a property that I need to stub. I
I have a class that has a method: -(NSInteger) getCityCountForState:(NSString *)state CityArray:(NSMutableArray *)cityArray {
I have a class that has an output() method which returns a matplotlib Figure
I have a class that has an list<Book> in it, and those Book objects

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.