Counterproposal for extending static members and constructors
Christophe Travert
travert at phare.normalesup.org
Thu Jul 12 14:23:56 PDT 2012
"Jonathan M Davis" , dans le message (digitalmars.D:172156), a écrit :
> On Thursday, July 12, 2012 18:25:03 David Piepgrass wrote:
>> I'm putting this in a separate thread from
>> http://forum.dlang.org/thread/uufohvapbyceuaylostl@forum.dlang.org
>> because my counterproposal brings up a new issue, which could be
>> summarized as "Constructors Considered Harmful":
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=8381
>
> I think that adding constructors to a type from an external source is
> downright evil. It breaks encapsulation. I should be able to constrain exactly
> how you construct my type. If you want to create a free function (e.g. a
> factory function) which uses my constructors, fine. But I'm completely against
> adding constructors externally.
The proposal is not that add constructors. It is to create a free
function (.make!Type(args)), that can called like a constructor, by
writing Type(args). That does not break encapsulation.
More information about the Digitalmars-d
mailing list