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

The Archive Base Latest Questions

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

i have a design issue, not complicated actually, but i would like to find

  • 0

i have a design issue, not complicated actually, but i would like to find an elegant way to solve it. And i thought about this:

Issue:
i have a class A that initialize and keep a collection of B

B is just an interface and must be implemented (so we have classes C,D,E,..).

in constructor A recive a bunch of dataset and must initialize some of B (also lot of different instantiation of same or different class) given each dataset. I would like A to not to know any implementation of B.

I have several working solution, but i was thinking about a kind of “delegate in the constructor”.
eg:

1. for each dataset, ds
2.   for each implementation of B, bi
3.     try to instantiate bi(ds)
4.       if success (means no exception)
5.         keep reference

this because the data and calculus i use to check if bi are pretty the same of initialization and being in a performance-critic application i would like to avoid doing that twice or doing it in collection class.
it would be really nice but obviously the problem is line 2…
…as well as the doubt about using exception for something that is not actually an exception. (line 4)

so what should be a pattern that
– let me evaluate data and construct all in one.
– avoid creating several “architectural-classes” i would like to avoid an explosion of classes ( kind of typical when exagerating with following design patterns java-style principles imho ) for such a simple task.
– as fast as possible.
– …is elegant 🙂

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

    Your pseudocode suggests a solution: your use of bi is nothing more than a factory function that takes a dataset as input and returns a B* as output. So, you really just need to take bi from a collection of std::function<B* (dataset)> objects.

    It would be easy enough to require that these factories are only ‘conditional’ factories: that sometimes they return valid objects, and sometimes they don’t, returning nullptr instead. This would let you avoid exceptions, and is more faithful to the intent of your usage.

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

Sidebar

Related Questions

Again I would like to get your opinion about a design issue. I have
I have a design issue and do not know how to go about it.
I have to design a GUI using Qt. I would like to draw multiple
I have this design which I cannot seem to get right, I would like
I have looked on line for information that would help me solve a design
I have a design issue which I can't just figure out how to solve.
I have a weird database design issue that I'm not sure if I'm doing
This is a design issue I keep running into, so I thought I would
I think I have a design issue, but I will ask you guys the
I have run into a bit of a design issue with my code. I

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.