Constructor (object-oriented programming)

Last updated

In class-based, object-oriented programming, a constructor (abbreviation: ctor) is a special type of function called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.

Contents

A constructor resembles an instance method, but it differs from a method in that it has no explicit return type, it is not implicitly inherited and it usually has different rules for scope modifiers. Constructors often have the same name as the declaring class. They have the task of initializing the object's data members and of establishing the invariant of the class, failing if the invariant is invalid. A properly written constructor leaves the resulting object in a valid state. Immutable objects must be initialized in a constructor.

Most languages allow overloading the constructor in that there can be more than one constructor for a class, with differing parameters. Some languages take consideration of some special types of constructors. Constructors, which concretely use a single class to create objects and return a new instance of the class, are abstracted by factories, which also create objects but can do so in various ways, using multiple classes or different allocation schemes such as an object pool.

Types

Parameterized constructors

Constructors that can take at least one argument are termed as parameterized constructors. When an object is declared in a parameterized constructor, the initial values have to be passed as arguments to the constructor function. The normal way of object declaration may not work. The constructors can be called explicitly or implicitly. The method of calling the constructor implicitly is also called the shorthand method.

classExample{public:Example();Example(inta,intb);// Parameterized constructor.private:intx_;inty_;};Example::Example()=default;Example::Example(intx,inty):x_(x),y_(y){}
Examplee=Example(0,50);// Explicit call.Examplee2(0,50);// Implicit call.

Default constructors

If the programmer does not supply a constructor for an instantiable class, Java compiler inserts a default constructor into your code on your behalf. This constructor is known as default constructor. You would not find it in your source code (the java file) as it would be inserted into the code during compilation and exists in .class file. The behavior of the default constructor is language dependent. It may initialize data members to zero or other same values, or it may do nothing at all. In Java, a "default constructor" refer to a nullary constructor that is automatically generated by the compiler if no constructors have been defined for the class or in the absence of any programmer-defined constructors (e.g. in Java, the default constructor implicitly calls the superclass's nullary constructor, then executes an empty body). All fields are left at their initial value of 0 (integer types), 0.0 (floating-point types), false (boolean type), or null (reference types)...

#include<iostream>classStudent{public:Student(inta=0,intb=0);// Default constructor.inta;intb;};

Copy constructors

Like C++, Java also supports "Copy Constructor". But, unlike C++, Java doesn't create a default copy constructor if you don't write your own. Copy constructors define the actions performed by the compiler when copying class objects. A Copy constructor has one formal parameter that is the type of the class (the parameter may be a reference to an object). It is used to create a copy of an existing object of the same class. Even though both classes are the same, it counts as a conversion constructor. While copy constructors are usually abbreviated copy ctor or cctor, they have nothing to do with class constructors used in .NET using the same abbreviation.

Conversion constructors

Conversion constructors provide a means for a compiler to implicitly create an object belonging to one class based on an object of a different type. These constructors are usually invoked implicitly to convert arguments or operands to an appropriate type, but they may also be called explicitly.

Move constructors

In C++, move constructors take an Rvalue reference to an object of the class, and are used to implement ownership transfer of the parameter object's resources.

Syntax

Memory organization

In Java, C#, and VB .NET, the constructor creates reference type objects in a special memory structure called the "heap". Value types (such as int, double, etc.) are created in a sequential structure called the "stack". VB .NET and C# also allow the use of the new operator to create value type objects, but these value type objects are created on the stack regardless of whether the operator is used or not.

In C++, objects are created on the stack when the constructor is invoked without the new operator, and created on the heap when the constructor is invoked with the new operator. Stack objects are deleted implicitly when they go out of scope, while heap objects must be deleted implicitly by a destructor or explicitly by using the delete operator.

Language details

Constructors are implemented in different programming languages in various ways, including:

C++

In C++, the name of the constructor is the name of the class. It returns nothing. It can have parameters like any member function. Constructor functions are usually declared in the public section, but can also be declared in the protected and private sections, if the user wants to restrict access to them.

The constructor has two parts. First is the initializer list which follows the parameter list and before the method body. It starts with a colon and entries are comma-separated. The initializer list is not required, but offers the opportunity to provide values for data members and avoid separate assignment statements. The initializer list is required if you have const or reference type data members, or members that do not have parameterless constructor logic. Assignments occur according to the order in which data members are declared (even if the order in the initializer list is different). [3] The second part is the body, which is a normal method body enclosed in curly brackets.

C++ allows more than one constructor. The other constructors must have different parameters. Additionally constructors which contain parameters which are given default values, must adhere to the restriction that not all parameters are given a default value. This is a situation which only matters if there is a default constructor. The constructor of a base class (or base classes) can also be called by a derived class. Constructor functions are not inherited and their addresses cannot be referenced. When memory allocation is required, the new and delete operators are called implicitly.

A copy constructor has a parameter of the same type passed as const reference, for example Vector(const Vector& rhs). If it is not provided explicitly, the compiler uses the copy constructor for each member variable or simply copies values in case of primitive types. The default implementation is not efficient if the class has dynamically allocated members (or handles to other resources), because it can lead to double calls to delete (or double release of resources) upon destruction.

classFoobar{public:Foobar(doubler=1.0,doublealpha=0.0)// Constructor, parameters with default values.:x_(r*cos(alpha))// <- Initializer list{y_=r*sin(alpha);// <- Normal assignment}private:doublex_;doubley_;};

Example invocations:

Foobara,b(3),c(5,M_PI/4);

On returning objects from functions or passing objects by value, the objects copy constructor will be called implicitly, unless return value optimization applies.

C++ implicitly generates a default copy constructor which will call the copy constructors for all base classes and all member variables unless the programmer provides one, explicitly deletes the copy constructor (to prevent cloning) or one of the base classes or member variables copy constructor is deleted or not accessible (private). Most cases calling for a customized copy constructor (e.g. reference counting, deep copy of pointers) also require customizing the destructor and the copy assignment operator. This is commonly referred to as the Rule of three.

C#

Example C# constructor:

publicclassMyClass{privateinta;privatestringb;// ConstructorpublicMyClass():this(42,"string"){}// Overloading a constructorpublicMyClass(inta,stringb){this.a=a;this.b=b;}}
// Code somewhere// Instantiating an object with the constructor aboveMyClassc=newMyClass(42,"string");

C# static constructor

In C#, a static constructor is a static data initializer. [4] :111–112 Static constructors are also called class constructors. Since the actual method generated has the name .cctor they are often also called "cctors". [5] [6]

Static constructors allow complex static variable initialization. [7] Static constructors are called implicitly when the class is first accessed. Any call to a class (static or constructor call), triggers the static constructor execution. Static constructors are thread safe and implement a singleton pattern. When used in a generic programming class, static constructors are called at every new generic instantiation one per type. [8] :38 [4] :111 Static variables are instantiated as well.

publicclassMyClass{privatestaticint_A;// Normal constructorstaticMyClass(){_A=32;}// Standard default constructorpublicMyClass(){}}
// Code somewhere// Instantiating an object with the constructor above// right before the instantiation// The variable static constructor is executed and _A is 32MyClassc=newMyClass();

ColdFusion Markup Language (CFML)

ColdFusion Markup Language (CFML) uses a method named 'init' as a constructor method.

Cheese.cfc

component{// propertiespropertyname="cheeseName";// constructorfunctionCheeseinit(requiredstringcheeseName){variables.cheeseName=arguments.cheeseName;returnthis;}}

Create instance of a cheese.

myCheese=newCheese('Cheddar');

Since ColdFusion 10, [9] CFML has also supported specifying the name of the constructor method:

componentinitmethod="Cheese"{// propertiespropertyname="cheeseName";// constructorfunctionCheeseCheese(requiredstringcheeseName){variables.cheeseName=arguments.cheeseName;returnthis;}}

Eiffel

In Eiffel, the routines which initialize new objects are called creation procedures. Creation procedures have the following traits:

Although object creation involves some subtleties, [10] the creation of an attribute with a typical declaration x: T as expressed in a creation instruction create x.make consists of the following sequence of steps:

In the first snippet below, class POINT is defined. The procedure make is coded after the keyword feature.

The keyword create introduces a list of procedures which can be used to initialize instances. In this case the list includes default_create, a procedure with an empty implementation inherited from class ANY, and the make procedure coded within the class.

classPOINTcreatedefault_create,makefeaturemake(a_x_value:REAL;a_y_value:REAL)dox:=a_x_valuey:=a_y_valueendx:REAL-- X coordinatey:REAL-- Y coordinate...

In the second snippet, a class which is a client to POINT has a declarations my_point_1 and my_point_2 of type POINT.

In procedural code, my_point_1 is created as the origin (0.0, 0.0). Because no creation procedure is specified, the procedure default_create inherited from class ANY is used. This line could have been coded create my_point_1.default_create . Only procedures named as creation procedures can be used in an instruction with the create keyword. Next is a creation instruction for my_point_2, providing initial values for the my_point_2's coordinates. The third instruction makes an ordinary instance call to the make procedure to reinitialize the instance attached to my_point_2 with different values.

my_point_1:POINTmy_point_2:POINT...createmy_point_1createmy_point_2.make(3.0,4.0)my_point_2.make(5.0,8.0)...

F#

In F#, a constructor can include any let or do statements defined in a class. let statements define private fields and do statements execute code. Additional constructors can be defined using the new keyword.

typeMyClass(_a:int,_b:string)=class// Primary constructorleta=_aletb=_bdoprintfn"a = %i, b = %s"ab// Additional constructorsnew(_a:int)=MyClass(_a,"")thenprintfn"Integer parameter given"new(_b:string)=MyClass(0,_b)thenprintfn"String parameter given"new()=MyClass(0,"")thenprintfn"No parameter given"end
// Code somewhere// instantiating an object with the primary constructorletc1=newMyClass(42,"string")// instantiating an object with additional constructorsletc2=newMyClass(42)letc3=newMyClass("string")letc4=MyClass()// "new" keyword is optional

Java

In Java, constructors differ from other methods in that:

Java constructors perform the following tasks in the following order:

  1. Call the default constructor of the superclass if no constructor is defined.
  2. Initialize member variables to the specified values.
  3. Executes the body of the constructor.

Java permit users to call one constructor in another constructor using this() keyword. But this() must be first statement. [11]

classExample{Example()// Non-parameterized constructor{this(1);// Calling of constructorSystem.out.println("0-arg-cons");}Example(inta)// Parameterized constructor{System.out.println("1-arg-cons");}}publicstaticvoidmain(String[]args){Examplee=newExample();}

Java provides access to the superclass's constructor through the super keyword.

publicclassExample{// Definition of the constructor.publicExample(){this(1);}// Overloading a constructorpublicExample(intinput){data=input;// This is an assignment}// Declaration of instance variable(s).privateintdata;}
// Code somewhere else// Instantiating an object with the above constructorExamplee=newExample(42);

A constructor taking zero number of arguments is called a "no-arguments" or "no-arg" constructor. [12]

JavaScript

As of ES6, JavaScript has direct constructors like many other programming languages. They are written as such

classFooBar{constructor(baz){this.baz=baz}}

This can be instantiated as such

constfoo=newFooBar('7')

The equivalent of this before ES6, was creating a function that instantiates an object as such

functionFooBar(baz){this.baz=baz;}

This is instantiated the same way as above.

Object Pascal

In Object Pascal, the constructor is similar to a factory method. The only syntactic difference to regular methods is the keyword constructor in front of the name (instead of procedure or function). It can have any name, though the convention is to have Create as prefix, such as in CreateWithFormatting. Creating an instance of a class works like calling a static method of a class: TPerson.Create('Peter').

programOopProgram;typeTPerson=classprivateFName:string;publicpropertyName:stringreadFName;constructorCreate(AName:string);end;constructorTPerson.Create(AName:string);beginFName:=AName;end;varPerson:TPerson;beginPerson:=TPerson.Create('Peter');// allocates an instance of TPerson and then calls TPerson.Create with the parameter AName = 'Peter'end.

OCaml

In OCaml, there is one constructor. Parameters are defined right after the class name. They can be used to initialize instance variables and are accessible throughout the class. An anonymous hidden method called initializer allows to evaluate an expression immediately after the object has been built. [13]

classpersonfirst_namelast_name=objectvalfull_name=first_name^" "^last_nameinitializerprint_endline("Hello there, I am "^full_name^".")methodget_last_name=last_nameend;;letalonzo=newperson"Alonzo""Church"in(*Hello there, I am Alonzo Church.*)print_endlinealonzo#get_last_name(*Church*)

PHP

In PHP version 5 and above, the constructor is a method named __construct() (notice that it's a double underscore), which the keyword new automatically calls after creating the object. It is usually used to automatically perform initializations such as property initializations. Constructors can also accept arguments, in which case, when the new statement is written, you also need to send the constructor arguments for the parameters. [1]

classPerson{privatestring$name;publicfunction__construct(string$name):void{$this->name=$name;}publicfunctiongetName():string{return$this->name;}}

In PHP, a class is only allowed to declare a maximum of one constructor method. Static methods, factory classes or optional constructor arguments are some ways to facilitate multiple ways to create objects of a PHP class.

Perl 5

In Perl version 5, by default, constructors are factory methods, that is, methods that create and return the object, concretely meaning create and return a blessed reference. A typical object is a reference to a hash, though rarely references to other types are used too. By convention the only constructor is named new, though it is allowed to name it otherwise, or to have multiple constructors. For example, a Person class may have a constructor named new, and a constructor new_from_file which reads a file for Person attributes, and new_from_person which uses another Person object as a template.

packagePerson;# In Perl constructors are named 'new' by convention.subnew{# Class name is implicitly passed in as 0th argument.my$class=shift;# Default attribute values, if you have any.my%defaults=(foo=>"bar");# Initialize attributes as a combination of default values and arguments passed.my$self={%defaults,@_};# Check for required arguments, class invariant, etc.if(notdefined$self->{first_name}){die"Mandatory attribute missing in Person->new(): first_name";}if(notdefined$self->{last_name}){die"Mandatory attribute missing in Person->new(): last_name";}if(defined$self->{age}and$self->{age}<18){die"Invalid attribute value in Person->new(): age < 18";}# Perl makes an object belong to a class by 'bless'.bless$self,$class;return$self;}1;

Perl 5 with Moose

In the Moose object system for Perl, most of this boilerplate can be omitted, a default new is created, attributes can be specified, and whether they can be set, reset, or are required. In addition, any extra constructor functionality can be included in a BUILD method which the Moose generated constructor will call, after it has checked the arguments. A BUILDARGS method can be specified to handle constructor arguments not in hashref / key => value form.

packagePerson;# enable Moose-style object constructionuseMoose;# first name ( a string) can only be set at construction time ('ro')hasfirst_name=>(is=>'ro',isa=>'Str',required=>1);# last name ( a string) can only be set at construction time ('ro')haslast_name=>(is=>'ro',isa=>'Str',required=>1);# age (Integer) can be modified after construction ('rw'), and is not required# to be passed to be constructor.  Also creates a 'has_age' method which returns# true if age has been sethasage=>(is=>'rw',isa=>'Int',predicate=>'has_age');# Check custom requirementssubBUILD{my$self=shift;if($self->has_age&&$self->age<18){# no under 18sdie"No under-18 Persons";}}1;

In both cases the Person class is instiated like this:

usePerson;my$p=Person->new(first_name=>'Sam',last_name=>'Ashe',age=>42);

Python

In Python, constructors are defined by one or both of __new__ and __init__ methods. A new instance is created by calling the class as if it were a function, which calls the __new__ and __init__ methods. If a constructor method is not defined in the class, the next one found in the class's Method Resolution Order will be called. [14]

In the typical case, only the __init__ method need be defined. (The most common exception is for immutable objects.)

>>> classExampleClass:... def__new__(cls,value):... print("Creating new instance...")... # Call the superclass constructor to create the instance.... instance=super(ExampleClass,cls).__new__(cls)... returninstance... def__init__(self,value):... print("Initialising instance...")... self.payload=value>>> exampleInstance=ExampleClass(42)Creating new instance...Initialising instance...>>> print(exampleInstance.payload)42

Classes normally act as 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 __new__ method is permitted to return something other than an instance of the class for specialised purposes. In that case, the __init__ is not invoked. [15]

Raku

In Raku, even more boilerplate can be omitted, given that a default new method is inherited, attributes can be specified, and whether they can be set, reset, or are required. In addition, any extra constructor functionality can be included in a BUILD method which will get called to allow for custom initialization. A TWEAK method can be specified to post-process any attributes already (implicitly) initialized.

classPerson {     hasStr$.first-nameisrequired; # First name (a string) can only be set at# construction time (the . means "public").hasStr$.last-nameisrequired;  # Last name (a string) can only be set at# construction time (a ! would mean "private").hasInt$.ageisrw;              # Age (an integer) can be modified after # construction ('rw'), and is not required# during the object instantiation.# Create a 'full-name' method which returns the person's full name.# This method can be accessed outside the class.methodfull-name { $!first-name.tc ~ " " ~ $!last-name.tc }      # Create a 'has-age' method which returns true if age has been set.# This method is used only inside the class so it's declared as "private"# by prepending its name with a !method !has-age { self.age.defined }        # Check custom requirementsmethodTWEAK {         ifself!has-age && $!age < 18 { # No under 18die"No person under 18";         }     } } 

The Person class is instantiated like this:

my$p0 = Person.new( first-name => 'Sam', last-name => 'Ashe', age => 42 ); my$p1 = Person.new( first-name => 'grace', last-name => 'hopper' ); say$p1.full-name(); # OUTPUT: «Grace Hopper␤»

Alternatively, the named parameters can be specified using the colon-pair syntax in Perl 6:

my$p0 = Person.new( :first-name<Sam>, :last-name<Ashe>, :age(42) ); my$p1 = Person.new( :first-name<Grace>, :last-name<Hopper> ); 

And should you have set up variables with names identical to the named parameters, you can use a shortcut that will use the name of the variable for the named parameter:

my$first-name = "Sam"; my$last-name  = "Ashe"; my$age        = 42; my$p0 = Person.new( :$first-name, :$last-name, :$age ); 

Ruby

In Ruby, constructors are created by defining a method called initialize. This method is executed to initialize each new instance.

irb(main):001:0> classExampleClassirb(main):002:1> definitializeirb(main):003:2> puts"Hello there"irb(main):004:2> endirb(main):005:1> end=> nilirb(main):006:0> ExampleClass.newHello there=> #<ExampleClass:0x007fb3f4299118>

Visual Basic .NET

In Visual Basic .NET, constructors use a method declaration with the name "New".

ClassFoobarPrivatestrDataAsString' ConstructorPublicSubNew(ByValsomeParamAsString)strData=someParamEndSubEndClass
' code somewhere else' instantiating an object with the above constructorDimfooAsNewFoobar(".NET")

See also

Notes

  1. Eiffel routines are either procedures or functions. Procedures never have a return type. Functions always have a return type.
  2. Because the inherited class invariant must be satisfied, there is no mandatory call to the parents' constructors.
  3. The Eiffel standard requires fields to be initialized on first access, so it is not necessary to perform default field initialization during object creation.

Related Research Articles

<span class="mw-page-title-main">Singleton pattern</span> Design pattern in object-oriented software development

In software engineering, the singleton pattern is a software design pattern that restricts the instantiation of a class to a singular instance. One of the well-known "Gang of Four" design patterns, which describes how to solve recurring problems in object-oriented software, the pattern is useful when exactly one object is needed to coordinate actions across a system.

In computer programming, lazy initialization is the tactic of delaying the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed. It is a kind of lazy evaluation that refers specifically to the instantiation of objects or other resources.

Generic programming is a style of computer programming in which algorithms are written in terms of data types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by the ML programming language in 1973, permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplicate code.

In class-based, object-oriented programming, an instance variable is a variable defined in a class, for which each instantiated object of the class has a separate copy, or instance. An instance variable has similarities with a class variable, but is non-static. An instance variable is a variable which is declared in a class but outside of constructors, methods, or blocks. Instance variables are created when an object is instantiated, and are accessible to all the constructors, methods, or blocks in the class. Access modifiers can be given to the instance variable.

In object-oriented (OO) and functional programming, an immutable object is an object whose state cannot be modified after it is created. This is in contrast to a mutable object, which can be modified after it is created. In some cases, an object is considered immutable even if some internally used attributes change, but the object's state appears unchanging from an external point of view. For example, an object that uses memoization to cache the results of expensive computations could still be considered an immutable object.

A method in object-oriented programming (OOP) is a procedure associated with an object, and generally also a message. An object consists of state data and behavior; these compose an interface, which specifies how the object may be used. A method is a behavior of an object parametrized by a user.

In object-oriented programming (OOP), the object lifetime of an object is the time between an object's creation and its destruction. Rules for object lifetime vary significantly between languages, in some cases between implementations of a given language, and lifetime of a particular object may vary from one run of the program to another.

In some programming languages, function overloading or method overloading is the ability to create multiple functions of the same name with different implementations. Calls to an overloaded function will run a specific implementation of that function appropriate to the context of the call, allowing one function call to perform different tasks depending on context.

In computer programming, a function object is a construct allowing an object to be invoked or called as if it were an ordinary function, usually with the same syntax. In some languages, particularly C++, function objects are often called functors.

This article compares two programming languages: C# with Java. While the focus of this article is mainly the languages and their features, such a comparison will necessarily also consider some features of platforms and libraries. For a more detailed comparison of the platforms, see Comparison of the Java and .NET platforms.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

In object-oriented programming, a member variable is a variable that is associated with a specific object, and accessible for all its methods.

A class in C++ is a user-defined type or data structure declared with keyword class that has data and functions as its members whose access is governed by the three access specifiers private, protected or public. By default access to members of a C++ class is private. The private members are not accessible outside the class; they can be accessed only through methods of the class. The public members form an interface to the class and are accessible outside the class.

In computer programming languages, the term default constructor can refer to a constructor that is automatically generated by the compiler in the absence of any programmer-defined constructors, and is usually a nullary constructor. In other languages it is a constructor that can be called without having to provide any arguments, irrespective of whether the constructor is auto-generated or user-defined. Note that a constructor with formal parameters can still be called without arguments if default arguments were provided in the constructor's definition.

C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by the publication year of the specification, though it was formerly named C++0x because it was expected to be published before 2010.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

This comparison of programming languages compares how object-oriented programming languages such as C++, Java, Smalltalk, Object Pascal, Perl, Python, and others manipulate data structures.

In computer programming, a constant is a value that is not altered by the program during normal execution. When associated with an identifier, a constant is said to be "named," although the terms "constant" and "named constant" are often used interchangeably. This is contrasted with a variable, which is an identifier with a value that can be changed during normal execution. To simplify, constants' values remains, while the values of variables varies, both hence their names.

The computer programming language, C#, introduces several new features in version 2.0. These include:

Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTSTEP operating system. Due to Apple macOS’s direct lineage from NeXTSTEP, Objective-C was the standard programming language used, supported, and promoted by Apple for developing macOS and iOS applications until the introduction of the Swift programming language in 2014. Thereafter, its usage has been consistently declining among developers and it has often been described as a "dying" language.

References

  1. 1 2 3 Constructors and Destructors, from PHP online documentation
  2. Data model, from Python online documentation
  3. https://stackoverflow.com/questions/1242830/constructor-initialization-list-evaluation-order Constructor
  4. 1 2 Albahari, Joseph. C# 10 in a Nutshell. O'Reilly. ISBN   978-1-098-12195-2.
  5. "Fabulous Adventures in Coding". Eric Lippert. 2013-02-06. Retrieved 2014-04-05.
  6. Expert .NET 2.0 IL Assembler. APress. 2006-01-01. ISBN   9781430202233 . Retrieved 2014-04-05.
  7. Static Constructor in C# on MSDN
  8. Skeet, Jon. C# in Depth. Manning. ISBN   978-1617294532.
  9. CFComponent
  10. Eiffel ISO/ECMA specification document
  11. Details on Constructor in java
  12. "Providing Constructors for Your Classes". Oracle Corporation. 2013. Retrieved 2013-12-20.
  13. OCaml manual
  14. Data model
  15. Data model