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

The Archive Base Latest Questions

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

I am developing a partition tool, and I am facing a problem in the

  • 0

I am developing a partition tool, and I am facing a problem in the design. I have a class (called CtrlFactories) that will read the MBR and build an object for each partition that is found in the MBR. I have a class for each type of partition and a Factory for each of them.

Here is how it looks like:

UML

(I’ve put only NTFS and FAT32 in the example, but I have one for each type of partition).

My idea was to put in the IFactory something like:

std::map< EPartType, IFactory* > mpFactories;

And build it in the constructor, or in some init function:

IFactory::IFactory()
{
    mpFactories[PART_NTFS] = new FactoryNTFS();
    mpFactories[PART_FAT32] = new FactoryFAT32();
    mpFactories[PART_EXT2] = new FactoryEXT2();
    ...
}

And in the “Build” function, do:

int CtrlFactories::Build()
{
    ...
    MBR mbr;
    BuildMBR( mbr );

    //... here I loop all the partitions found...
    for( /*each partition*/ )
    {
        IPartition* part = mpFactories[ mbr.GetPartType() ]->Build( mbr.PartPosition() );
        //..and store each partition somewhere
    }
}

The point is: I have lots of partition types (> 100), and in most of cases, the user will only have two or three different types of partitions in the HD. So it seems like a waste of time and memory to allocate all the factories and not using most of them. I think that a lazy initialization would be much better here, but then I would need somewhere a code like:

    switch( mbr.GetPartType() )
    {
    case PART_NTFS:
        if ( mpFactories[ PART_NTFS ] == NULL )
            mpFactories[PART_NTFS] = new FactoryNTFS();
        break;       

    case PART_FAT32:
        if ( mpFactories[ PART_32 ] == NULL )
            mpFactories[PART_32] = new Factory32();
        break;       

    ...
    }

}

And that very long switch/case would add too much ciclomatic complexity to the code (even the code being easy to understand).

So, is there a better solution for the problem, that can avoid the very long “switch/case” and that does not waste resources?

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

    One approach would be to implement the factories with the Singleton pattern. Have a static Instance() method on each factory class that manages it’s instantiation. Then in your map you could store a function pointer to that method.

    In your Build() code you’re then looking up a pointer to the Instance() method for the factory for each partition you come across. Use that pointer to get the actual factory you need, and then proceed from there.

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

Sidebar

Related Questions

Developing a network application, I have a Connection class that manages sending and receiving
I am developing a partition disk program, and for me to read the \\\\.\\PhysicalDrive0
Developing for iPhone, I have a collection of points that I need to make
Developing an application for Android, i want to record data that will be usefull
Developing ios app. I have an object class Product.h and .m respectively along with
Developing a little survey webapp, ran into problem that deals with ranges for rating
Developing Java, you have always learned that its best to create an ArrayList by
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing a project of mine I realize I have a need for some level
developing iphone app, I have used a UIImageview and i have set an image

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.