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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:10:33+00:00 2026-05-15T22:10:33+00:00

Please don’t mind about the syntax. I thought of making the post as brief

  • 0

Please don’t mind about the syntax. I thought of making the post as brief as possible.

We have a class hierarchy as below.

// abstract class.   
class BaseProd   
// concrete classes.   
class Prod1 : public BaseProd   
class Prod2 : public BaseProd   
class Prod3 : public BaseProd   

Each class has 3 sub classes like, Prod1New, Prod1Cancel and Prod1Modify the same case for the other 2 classes. Now, since New, Cancel and Modify are the events, we can represent them using enum.

The problem is, each class has lot of methods that are very specific to each event. Eg.

getRec(); // has specific implementations for each event.   

Let’s say there is something like process method.

void Prod1::process()
{
   getRec(); // Each derived class overrides the method.   
   getPayment();// Each derived class overrides the method.   
}  

This way, we have 13 classes for 3 products having 3 events each.
If we have 2 more products the classes would grow by 8.

Can we have any alternate approach to this hierarchy?

UPDATE:
The suggestion made by Tyler works only when
Prod1’s NewEvent and Prod2’s NewEvent have the same implementation. Right? But in this case it is not. Atleast for some of the methods it is not.

  • 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-15T22:10:33+00:00Added an answer on May 15, 2026 at 10:10 pm

    I don’t see why the New, Cancel, and Modify messages should be subclasses of the products that they apply to. This doesn’t satisfy the “is-a” relationship that should define inheritance. If class D inherits from class B, the statement “Every D is a B” should make sense and always be true. “A Prod1 is a BaseProd” (i.e. “Every specific product is a product”) — that is true and makes sense.

    But in the case of events, a Prod1Cancel is not a Prod1. It doesn’t make sense to say “Every product1 cancellation event is a product1.” Rather, a Prod1Cancel is an event relating to Prod1, so it makes more sense that the Prod1Cancel class should contain a Prod1 object, rather than inheriting from it.

    Since all of your products inherit from a BaseProd class, you should really only need one class for each event, and not one class per event per product type, if you define your event classes like this:

    class NewProductEvent {
    
       public:
    
         explicit NewProductEvent(BaseProd* product)
           : m_product(product)
         { /* ... */ }
    
         void getRec() { /* ... */ }
         void getPayment() { /* ... */ }
    
       private:
    
         BaseProd* m_product; // Use this to access the data that the event 
                              // needs from the product
    };
    

    Then, inside your Prod1::process() method, you could generate a NewProductEvent event for the current object, and call the appropriate methods on it:

    void Prod1::process()
    {
      NewProductEvent event(this);
    
      event.getRec();
      event.getPayment();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please don't mind my question since I don't know much about software because I
I am new to xml , so please don't mind if it is too
Please don't answer the obvious, but what are the limit signs that tell us
Now, I know this is completely subjective, so please don't flame me. I've never
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
Please don't laugh, but I'm maintaining an Access database with an external customer table
Wait- please don't suggest the Validation plugin until reading.... I've looked into it.. I'm
Hi all C experts (please don't shoot, I'm no C programmer anymore but from
Update3: If you like this posting please don't upvote me but upvote the genius
Still teaching myself python so please don't hate me if my code is terrible...

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.