Content deleted Content added
Line 70:
* In [[Moose perl|Moose object system]] for Perl, constructors (named ''new'') are automatically created and are extended by specifying a ''BUILD'' method.
* In [[Visual Basic .NET]], the constructor is called "<code>New</code>".
* In [[Python (programming language)|Python]], the constructor is split over two methods, "<code>__new__</code>" and "<code>__init__</code>". The <code>__new__</code> method is responsible for allocating memory for the instance, and receives the class as an argument (conventionally called "<code>cls</code>"). The <code>__init__</code> method (often called "the initialiser") is passed the newly created instance as an argument (conventionally called "<code>self</code>").<ref>[
* [[Object Pascal]] constructors are signified by the keyword "<code>constructor</code>" and can have user-defined names (but are mostly called "<code>Create</code>").
* In [[Objective-C]], the constructor method is split across two methods, "<code>alloc</code>" and "<code>init</code>" with the <code>alloc</code> method setting aside (allocating) memory for an instance of the class, and the <code>init</code> method handling the bulk of initializing the instance. A call to the method "<code>new</code>" invokes both the <code>alloc</code> and the <code>init</code> methods, for the class instance.
Line 494:
=== Python ===
In [[Python (programming language)|Python]], constructors are defined by one or both of <code>__new__</code> and <code>__init__</code> methods. A new instance is created by calling the class as if it were a function, which calls the <code>__new__</code> and <code>__init__</code> methods. If a constructor method is not defined in the class, the next one found in the class's [[C3 linearization|Method Resolution Order]] will be called.<ref>[
In the typical case, only the <code>__init__</code> method need be defined. (The most common exception is for immutable objects.)
Line 516:
</source>
Classes normally act as [[Factory (object-oriented programming)|factories]] for new instances of themselves, that is, a class is a callable object (like a function), with the call being the constructor, and calling the class returns an instance of that class. However the <code>__new__</code> method is permitted to return something other than an instance of the class for specialised purposes. In that case, the <code>__init__</code> is not invoked.<ref>[
=== Ruby ===
|