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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:28:11+00:00 2026-05-19T05:28:11+00:00

Consider the (highly simplified) following case: class Dispatcher { public: receive() {/*implementation*/}; // callback

  • 0

Consider the (highly simplified) following case:

class Dispatcher {
public:
    receive() {/*implementation*/};  // callback
}

class CommInterface {
public:
    send() = 0;  // call
}

class CommA : public CommInterface {
public:
    send() {/*implementation*/};
}

Various classes in the system send messages via the dispatcher. The dispatcher uses a comm to send. Once an answer is returned, the comm relays it back to the dispatcher which dispatches it back to the appropriate original sender. Comm is polymorphic and which implementation to choose can be read from a settings file.

Dispatcher has a dependency on the comm in order to send. Comm has a dependency on dispatcher in order to callback. Therefor there’s a circular dependency here and I can’t seem to implement the dependency injection principle (even after encountering this nice blog post).

Updates:

  1. Comm depends on 3rd party code (as
    there are various 3rd parties, Comm
    is polymorphic). Comm has a receive
    function of its own and it relays it
    to Dispatcher’s receive function (in
    practice there are multiple such
    functions with various parameter
    sets). A possible call would be:

    CommA::receive_3(/*parameters set a*/) {
        /* some parameters manipulation */
        dispatcher_ptr->receive_5(/*parameters set b*/);
        dispatcher_ptr->receive_6(/*parameters set c*/);
    }
    
  2. At least currently Dispatcher “knows” which Comm to use using a parameter it receives in its constructor, therefor it can’t initialize Comm in its initialization list. It could have just as easily received a shared_ptr to Comm and be done with it, but that would require first to initialize Comm and Comm requires a pointer to Dispatcher for the callbacks… Of course I could implement a function in Comm named setDispatcher(Dispather* dispatcher_ptr) but wouldn’t that go against Dependency Injection?
  • 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-19T05:28:12+00:00Added an answer on May 19, 2026 at 5:28 am

    I realized that where many classes use the Dispatcher instance, only the Dispatcher instance uses the CommA instance. Therefore the Dispatcher’s dependency on CommA should not be externalized, i.e. CommA object should not be “injected” to the Dispatcher any more than any other internally defined variable within Dispatcher.

    For a minute I thought my question might have been misleading, but then I realized that it originated from a very basic misunderstanding about Dependency Injection. Dependencies should be externalized only if they cannot be internally managed. Therefore I’m leaving this question and this answer for posterity 🙂

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

Sidebar

Related Questions

Consider these classes. class Base { ... }; class Derived : public Base {
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception
Consider the following 2 queries: select tblA.a,tblA.b,tblA.c,tblA.d from tblA where tblA.a not in (select
Consider the need to develop a lightweight desktop DB application on the Microsoft platforms.
Consider: List<String> someList = new ArrayList<>(); // add "monkey", "donkey", "skeleton key" to someList
Consider this problem: I have a program which should fetch (let's say) 100 records
Consider these two function definitions: void foo() { } void foo(void) { } Is
Consider the Oracle emp table. I'd like to get the employees with the top
Consider an indexed MySQL table with 7 columns, being constantly queried and written to.

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.