Is this a good pattern for allocation?

JS js.mdnq at gmail.com
Mon Aug 5 01:11:58 PDT 2013


On Monday, 5 August 2013 at 07:15:30 UTC, Tobias Pankrath wrote:
> On Monday, 5 August 2013 at 01:47:26 UTC, JS wrote:
>> Anyways, is this a bad or good way and how can I call Factory 
>> to get a new object? (I know that ther is .init and other 
>> stuff that can be used by Factor/New. I'm just trying to get 
>> the skeleton to compile and make sure there are not going to 
>> be major issues in the future.
>
> I wouldn't use inheritance, but something that involves a 
> template function and std.conv.emplace and handles all of your 
> types uniformly.

The purpose of inheritance is to allow one to modify the 
allocation scheme if necessary and to have a common interface 
which looses the dependency on any standard library, D, or the 
GC. (e.g., instead of having to change new every place it occurs 
one just has to change it either in the factory or in the New 
method).

I guess you mean that I should use a template as a factory 
instead of an interface? I'll have to think about it to see what 
the pro's and con's of each are. The interface pattern should 
include the template pattern though. (after all, the interface is 
parameterized...)


More information about the Digitalmars-d-learn mailing list