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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:08:19+00:00 2026-05-15T20:08:19+00:00

I am generating a sequence of Step objects that differ by Type and data

  • 0

I am generating a sequence of Step objects that differ by “Type” and data contained within. e.g:

The Step objects should basically be structs that look like this

{ GRAB, CASCADE_ONE, FACEUP, SOMEOTHERDATA },
{ DROP, DECK,  FACEDOWN, MOREDATA, ANDSOMEMORE },
{ MOVE, 34, 89 },

where GRAB, MOVE and DROP indicate StepType:

typedef enum
{
     GRAB,
     DROP,
     MOVE
}StepType;

As you can see, depending on StepType, these structs each have variable numbers of data fields after the StepType.

I plan to iterate over a sequence of these structs and perform a particular action based on the StepType field. My first hunch is that these should be objects of classes derived from an abstract Step class – i.e. I should create a GrabStep class, a MoveStep class and a DropStep class.

Is this a good design and if so should I create them using a factory method? If a factory method is the way to go, then how to initialise the fields within the objects?

  • 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-15T20:08:19+00:00Added an answer on May 15, 2026 at 8:08 pm

    You don’t need the factory pattern for this. But creating an abstract Step class is a good start:

    class Step
    {
    private:
        // The presence of a pure virtual makes this class abstract.
        virtual void DoAction() = 0;
    public:
        virtual ~Step() {} // Needed if you are going to delete via a Step* pointer
        void Action() { DoAction(); } // Template method pattern
    };
    
    // All other classes derive publicly from Step, since they all have an "is-a"
    // relationship with Step (i.e. a GrabStep "is-a" Step).
    class GrabStep : public Step
    {
    private:
        void DoAction() { /* Do whatever a GrabStep does */ };
        // Data relevant to GrabStep
    };
    
    class MoveStep : public Step
    {
    private:
        void DoAction() { /* Do whatever a MoveStep does */ };
        // Data relevant to MoveStep
    };
    
    class DropStep : public Step
    {
    private:
        void DoAction() { /* Do whatever a DropStep does */ };
        // Data relevant to DropStep
    };
    

    Then, you can iterate over these things without having to know their exact types:

    // Example:
    std::vector<Step*> seq; // or some other container
    // Note that we are storing Step* pointers in a container instead of Step
    // objects. This is needed for polymorphism to work.
    // ...
    seq.push_back(new GrabStep);
    seq.push_back(new MoveStep);
    seq.push_back(new DropStep);
    // ...
    for(std::vector<Step*>::iterator i = seq.begin(); i != seq.end(); ++i)
    {
        // Will call the proper version of DoAction() depending on the actual type.
        (*i)->Action();
    }
    // ...
    // After we are done, clean up after ourselves. This is needed because
    // std::vector does not delete the pointees.
    for(std::vector<Step*>::iterator i = seq.begin(); i != seq.end(); ++i)
    {
        delete (*i); // Safe because Step has a virtual destructor.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm generating auto incremental code through a PHP script. The sequence goes like this,
Generating normal columnar data in excel file is quite easy but does any one
Am generating a hidden fields like so: @helper.input(_form(userID), '_label-> None) { (id, name, value,
When generating VS2010 targets with CMake, I would like the /LTCG flag turned on
I would like to know the general practice used in the industry for generating
I am especially interested in generating code from sequence diagrams and vice versa- ie.,
I understand that unique IV is important in encrypting to prevent attacks like frequency
I have a task of generating video from a sequence of images in my
I am looking for help with generating this plot from a sequence of ones
I'm trying to increment a sequence in sqlite3. Basically, I'm using the sequence as

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.