Constructor (object-oriented programming): Difference between revisions

Content deleted Content added
See also: Added one more link
Notes are now separated from the references
Line 295:
In [[Eiffel (programming language)|Eiffel]], the routines which initialize new objects are called '''creation procedures'''. Creation procedures have the following traits:
 
* Creation procedures have no explicit return type (by definition of '''procedure''').<ref>{{Efn|Eiffel '''routines''' are either '''procedures''' or '''functions'''. Procedures never have a return type. Functions always have a return type.</ref>}}
* Creation procedures are named.
* Creation procedures are designated by name as creation procedures in the text of the class.
* Creation procedures can be explicitly invoked to re-initialize existing objects.
* Every effective (i.e., concrete or non-abstract) class must designate at least one creation procedure.
* Creation procedures must leave the newly initialized object in a state that satisfies the class invariant.<ref>{{Efn|Because the inherited class invariant must be satisfied, there is no mandatory call to the parents' constructors.</ref>}}
 
Although object creation involves some subtleties,<ref name="eiffel standard">[http://www.ecma-international.org/publications/standards/Ecma-367.htm Eiffel ISO/ECMA specification document]</ref> the creation of an attribute with a typical declaration <code lang="eiffel">x: T</code> as expressed in a creation instruction <code lang="eiffel">create x.make</code> consists of the following sequence of steps:
 
* Create a new direct instance of type <code lang="eiffel">T</code>.<ref>{{Efn|The Eiffel standard requires fields to be initialized on first access, so it is not necessary to perform default field initialization during object creation.</ref>}}
* Execute the creation procedure <code lang="eiffel">make</code> to the newly created instance.
* Attach the newly initialized object to the entity <code lang="eiffel">x</code>.
Line 530:
* [[Destructor (computer science)|Destructor]]
* [[Global constructor]]
 
== Notes ==
{{Notelist}}
 
== References ==
{{reflistReflist}}
 
[[Category:Method (computer programming)]]