mardi 2 mai 2023

What design pattern should I use when a base class creates child classes?

I'm writing in c++, I have a base class let's call it base, that has 2 children classes. the requierements are:

  1. Singleton, also the base class can't be initialized as object
  2. the base class has a function to create an instance, which will choose on runtime what child object to create (not sure if this is a good logic, but the base class is responsible on choosing and initiating a child).
  3. The base class also holds multiple functions that the children share.
  4. Then there are multiple pure virtual funtions that only the children implement.

I'm thinking of some combination of singleton + factory patterns, but not sure how to use factory here.

Aucun commentaire:

Enregistrer un commentaire