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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:26:18+00:00 2026-06-10T13:26:18+00:00

What is you experience with using callbacks in object-oriented programs? Do callbacks lead to

  • 0

What is you experience with using callbacks in object-oriented programs? Do callbacks lead to a code that is higher quality (easier to understand, extend and maintain)? Or should callbacks be rather avoided in object-oriented code?

To illustrate the issue, consider following two ways in which a class can notify that it finished processing asynchronous task (The code is in C++ using plain function pointers as callbacks, but these are just details, the question is about object oriented practices):

  1. Define an interface for notification and pass an object implementing this interface to an asynchronous reader:

    class IReadFinishedListener {
       virtual void readDone() = 0;
    };
    
    class ReaderA {
      void asyncRead(IReadFinishedListener& readFinished);
    };
    
  2. Pass a callback to a reader:

    class ReaderB {
       void asyncRead(void (*readFinishedCallback)(void));
    };
    

The first solution seems more pure from the object oriented perspective. You have an explicitly defined interface, which documents what the code implementing the interface does. You can easily find classes that implement the interface, the code can be easier to follow.

Second solution is more lightweight, it does not require additional interface, which is often hard to design and name. It also seems more flexible, because it can reduce coupling between the class that handles reading and a code that is notified when reading finishes. But, the code can become harder to follow because there is no explicit interface that documents which classes can handle the notification.

  • 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-10T13:26:20+00:00Added an answer on June 10, 2026 at 1:26 pm

    I think first variant is better in OOP, and that is why:

    1. In OOP, as I think, objects are paramount, not actions, and with this ideology it seems more correctly, when objects do something through other objects.
    2. You declare some entity which has it’s own area of ​​responsibility, and you have ability to change this area flexible and simple.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a piece of code that I am working on using function
Does anyone have any experience using Cucumber and the code coverage tool SimpleCov? I'd
I have some experience using parallel extensions in .Net development, but I was looking
Does anyone have any experience using PHP to send an sms via skype I
Has anyone had any experience using Adobe Air to create BitTorrent application? Is there
Anyone with experience using jPicker colorpicker in a WordPress Custom Theme options panel. I
I have very little experience using Sharepoint but a good amount using Visual Studio
Has anyone had experience using SSL with net.tcp binding in WCF? Ive read its
I have a small amount of experience using SVN on my development projects, and
I'm new to grails, but have previous experience using .net with c# and linq

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.