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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:46:45+00:00 2026-05-24T05:46:45+00:00

Problem description: I need to implement 2 classes like following: class A1 { common_method1();

  • 0

Problem description:

I need to implement 2 classes like following:

class A1 {
 common_method1();
 common_method2();
 foo1();
};

class A2 {
 common_method1();
 common_method2();
 foo2();
};

foo1() and foo2() has different logic.
foo1() and foo2() may have different args and return values.
common methods are the same OR have similar logic.

Target:
To implement factory that is able to generate A1 or A2 objects.
After call to factory::create() use foo1() or foo2() method respectively to the type of the object generated.

Question
How better to implement such logic in C++ C++/CLI?

THANKS!

  • 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-24T05:46:47+00:00Added an answer on May 24, 2026 at 5:46 am

    I think this is definitely a standard inheritance pattern. Create a base class Parent, which implements common_method1 and common_method2. Create classes A1 and A2 which inherit from Parent.

    If you need to do some special casing in one of the common_method1 or common_method2 methods in either A1 or A2, make the methods virtual in Parent.

    Implement foo1 and foo2 in respectively A1 and A2.

    EDIT: If I understand you correctly, you want to create a factory that returns a Parent type reference (abstract class). If you want to always foo1 on A1 objects, and foo2 on A2 objects, simply create a virtual method bar in the Parent interface, which, overriden in A1, will simply call foo1, and, overriden in A2, will simply call foo2.

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

Sidebar

Related Questions

Uhm I'm not sure if anyone has encountered this problem a brief description is
Given the following xml fragment: <Problems> <Problem> <File>file1</File> <Description>desc1</Description> </Problem> <Problem> <File>file1</File> <Description>desc2</Description> </Problem>
I would like to build a generic class that I can use to implement
Having the following hierarchical text data input (JunOS-like, in fact) I need to parse
Here is the problem description of my design. There is a class A (Singleton)
Problem description: Read an xml file, traverse to a particular node (element), if it
Expanding this question on how I learnt to pass from problem description to code
SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without
I'm having a problem with this: -(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u { I'm
Ok here is my problem : Before i start the description, let me 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.