Consider the following interface (dumb pointers are used because we are still in C ++ 98)
class WidgetMaker {
virtual Widget* makeWidget() = 0;
};
With the next likely implementation
class SpecificWidgetMaker: public WidgetMaker {
Widget* makeWidget() {
return new SpecificWidget();
}
};
A widget is a base class with a virtual destructor, SpecificWidget extends it. My colleagues say that the WidgetMaker interface should contain the following method
virtual void freeWidget(Widget* widget);
The rationale is that this way we do not force the makeWidget implementation to use the standard new distribution, they can use their own pool allocator or always return the same global instance if the widget does not have statelessness or something else.
, , , - , KISS YAGNI, ( 20 ) _ptr . ? , factory ?