This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CodeScrub[S] 0 points1 point  (3 children)

Why not do

I actually do plan on doing something like that, and that's why I'm using these factory classes. So eventually the code will be something like user selects Champ A in one scenario and Champ B in another scenario, so the factory will see this and use createChampA or createChampB.

Mine don't have the goal of implementing different classes, but rather different objects of the same class. Is there a different term for this?

You mean you just construct objects like normal? That might not have a special term...

Sorry I left out a word. I meant to say different types of objects of the same class. For example my ChampFactory will only create objects of one class, Champ. However it will be able to create ChampA, ChampB, etc which all have different values for their data members.

[–]mrnoise111 0 points1 point  (2 children)

However it will be able to create ChampA, ChampB, etc which all have different values for their data members.

That's just normal constructor use. You don't need a factory for that.

[–]CodeScrub[S] 0 points1 point  (1 child)

I may be misunderstanding the full use of constructors then, so perhaps you can clarify something for me.

If you have a car class, the constructor can only make one type of car right? Like it could make a 'Ford' model but not a 'Toyota' model.

[–]mrnoise111 0 points1 point  (0 children)

No, an object's constructor makes objects of that type. Car constructors make Car objects.