Answer the question
In order to leave comments, you need to log in
C++, Abstract Factory and Strategy patterns?
Are there ready-made libraries for implementing such code?
BaseHandler::registerType<InfoHandler>(1);<br>
BaseHandler::registerType<AuthHandler>(2);<br>
<br>
BaseHandler* handler = BaseHandler::factory(1); //Находим обработчик по ID<br>
BaseHandler* handler = 0;<br>
<br>
switch(type)<br>
{<br>
case 1:<br>
handler = new InfoHandler;<br>
break;<br>
<br>
case 2:<br>
handler = new AuthHandler;<br>
break;<br>
}
Answer the question
In order to leave comments, you need to log in
I have not seen such ready-made libraries, but it is impossible to take the implementation beyond the headers for sure. A template class only generates a concrete class the first time it is used. As far as I remember, if you immediately implement a specific instance in the header, then you can move the code to a cpp file, but then the meaning of the templates is lost.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question