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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:16:07+00:00 2026-05-24T04:16:07+00:00

I am designing a set of small C++ classes which all implement a single

  • 0

I am designing a set of small C++ classes which all implement a single interface. Let’s call the interface IHandler. It has only one method.

There are a bunch of Handlers, one for each type in our domain. Let’s call them FooHandler, BarHandler etc. There is also a PassiveHandler, which does nothing (this is used for domain objects who don’t need to be handled).

So our hierarchy could look nice and flat like this:

IHandler
|-PassiveHandler
|-FooHandler
|-BarHandler
| (...)
|-BazHandler

However, all the handlers need a data member, let’s call it domainObject, so I thought about extracting a common superclass Handler that just holds this object.

Also, all the handlers except PassiveHandler needs a second data member, let’s call it infoObject, so I thought about extracting another common superclass ActiveHandlerto hold this object. Now the hierarchy is looking a lot deeper, but we have removed some duplication.

IHandler
|-Handler
| |-PassiveHandler
| |-ActiveHandler
|   |-FooHandler
|   |-BarHandler
|   | (...)
|   |-BazHandler

Would you go with the shallow design, where the domainObject member declaration is duplicated in all classes, and the infoObject member declaration in most? Or would you prefer the more complicated hierarchy, where duplication is removed? Is it worth it just for these data members?

  • 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-24T04:16:09+00:00Added an answer on May 24, 2026 at 4:16 am

    I’d choose the second, more hierarchical solution. Not only because the data member, but also because of your remark: “this is used for domain objects who don’t need to be handled”. Sounds like this is more like a nul-handler, which does nothing at all. Seems to be a good thing to pull it out of the tree, because you’re likely to introduce other functionality too that will only apply to ‘active handlers’.

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

Sidebar

Related Questions

We are designing set of web services which will return XML string in response.
I am designing a set of 'service' layer objects (data objects and interface definitions)
I've been using for a while a small git repository that has been set-up
When defining a custom operator from the limited set of single-character operators that can
Designing forms has always been fun, but getting them to send email on the
When designing LINQ classes using the LINQ to SQL designer I've sometimes needed to
When designing a collection class, is there any reason not to implement locking privately
Lets say I am designing a tool foobuzzle (foobuzzle's exact job is to set
Problem* Given some data (text) which has style applied to it with a loosely
I'm designing an iPhone app that features a rather large set of onscreen rounded

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.