On www.dofactory.com I found a real Factory template example. But the code generates a warning in ReSharper about calling the virtual member in the constructor.
The warning code is as follows:
abstract class Document { private List<Page> _pages = new List<Page>();
In the consumption code, you can simply use:
Document document = new Resume();
I understand why it is a bad idea to call a virtual member in the constructor (as explained here ).
My question is how can you reorganize this to use the Factory pattern, but without invoking the virtual member in the constructor.
If I just deleted the CreatePages call from the constructor, the consumer would have to explicitly call the CreatePages method:
Document document = new Resume(); document.CreatePages();
I like the situation much more when creating a new Resume is all that is needed to create pages containing resumes.
c # design-patterns factory-method
comecme
source share