Ask coding questions

← Back to all posts
How can I avoid long switch statements for a factory method?
JustinWu (4)

I have this program which relies on a factories comprised of switch statements and ids(integers) to create objects. I don't want to deal with a potentially long switch statement. Is there a way how I can avoid this considering my program's structure?

Commentshotnewtop
PattanAhmed (1102)

@JustinWu Hi,
Can we know Which file are you talking about in your question?
Hope this helps.

JustinWu (4)

@PattanAhmed characterCreator.h and objectCreator.h

PattanAhmed (1102)

@JustinWu Hi,
Can you go through the answer to this question?
Click here and this too

Please try to understand the answer well!
Hope this helps.
Please mark my answer if this helps

DynamicSquid (3549)

which file are you taking about?

JustinWu (4)

@DynamicSquid objectCreator.h and characterCreator.h

DynamicSquid (3549)

@JustinWu hmm... it's going to be tough to use something else since you have the new keyword in their. I don't think there's an alternative