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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:43:27+00:00 2026-05-13T20:43:27+00:00

I’m studying some source codes and I’m just wondering why a class (or classes)

  • 0

I’m studying some source codes and I’m just wondering why a class (or classes) is often implemented this way:


class EventHandler
{
...
    EventDispatcher* m_Dispatcher;
    virtual bool ProcEvent( EventHandler* Sender, int Task, int Event, void* Param );
...
};

class ClassA: public EventHandler
{
...
    ClassA* m_Impl;
    ClassA* m_Iface;
...
public:
    // virtual functions
    virtual bool ProcEvent( EventHandler* Sender, int Task, int Event, void* Param );
    virtual void OnDataWritten(const PIOResult&) {;}
    ...

    // sample functions
    void SetImplement( ClassA* aImpl );
    void SetInterface( ClassA* aIface );
    ClassA* GetImplement() { return m_Impl; }
    ClassA* GetInterface() { return m_Iface; }
    bool GetData( list& aList );
};

// Implementation of some sample functions; Most of its function contain more
// or less the same format as below, with the return m_Impl->XXX having the same
// name as the function being defined (e.g. A::XXX)
bool ClassA::GetData( list< Data >& aList )
{
    if( m_Impl )
        return m_Impl->GetData( aList );
    else
        return false;
}

class ClassAFactory: public EventHandler
{
private:
    ClassAFactory* m_Impl;
    ClassAFactory* m_Iface;

protected:
    virtual ClassA* MakeTransport();

    virtual bool ProcEvent( EventHandler* Sender, int Task, int Event, void* Param );
    virtual ClassA* CreateClassA() { return 0; }

...
};

// In some member function of ClassB (ClassB inherits ClassA)

switch( status )
{
    case 1:
        GetInterface()->OnDataWritten();
    case 2:
        // ...
};


I believe it’s for some design pattern but I’m not familiar with it. It could help me understand if I know what it is. Can anyone help me point out which it could be or what is the use of these classes such that it is implemented this way?

I think it’s for some event handling and used together with some factory but I’m not sure.

  • 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-13T20:43:27+00:00Added an answer on May 13, 2026 at 8:43 pm

    I am afraid the names used do not have the usual meaning, so without examples of what is put in or how they are used, it’s going to be difficult to guess.

    There are 2 design patterns that you should check, that make heavy use of this kind of self-recursion (at class level*):

    • The Decorator Pattern
    • The Composite Pattern

    And I am afraid that you are looking at something that fails to emulate either of those.

    In the Decorator, the point is to add functionality. To this end you have an Interface of which derives a Concrete class and a Wrapper interface. Then various wrappers will derive of Wrapper and you can chain them:

    Interface* interface = new Wrapper2( new Wrapper1 ( new Concrete() ) );
    

    Each wrapper add some functionality, whereas here we only have perfect forwarding… so it’s not a Decorator.

    The Composite pattern is different. Its goal is to hide whether you treat with a collection of elements or a single element. The usual example is a tree: you can apply operations either to an entire subtree or just a leaf node if it’s implemented with a Composite Pattern.

    Once more, there is not such thing here.

    So my best guess is that you have either a wild design (perhaps a misguided attempt to emulate a well-known pattern) or you haven’t given enough information (source code) for us to figure out the role. It seems strange anyway.

    *Note: by self-recursion at class level I mean that an object of class A points to another object of class A, but this does not mean (certainly) that it points to the same instance… otherwise we would have a Stack Overflow (pun intended). This not the same instance bit is certainly worth checking during the SetImplementation call: note that any cyclic reference would cause death by recursion.

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

No related questions found

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.