Skip to main content
constructor

constructor

3 6.0
A special function in a computer program that makes and sets up a new object
  • noun
  • /kənˈstrʌktər/
  • Specialized
translation icon : constructor
  • Every time you create an instance of a class, the constructor is called to set up the initial state.
  • type constructor

Does it use a builder object or a constructor or a factory or something else?

Autoplay Next

Examples

  • So for that to happen on Python, which is slightly different from other programming languages, you need to define a constructor here in it.

  • Now we'll have the constructor, which is what we're going to call to initialize Bob, and we're going to pass the number of integers I want Bob to hold as an argument.

  • OK, I want to write a constructor function.

  • Then you are able to make your fields final and set them in your constructor.

    Blog text (24)
  • Is there some way to number the instances of a call to the constructor?

    Blog text (25)
  • Does it use a builder object or a constructor or a factory or something else?

  • A more sophisticated approach is to make the constructor private and construct instances in factory methods.

    Blog text (24)
  • I didn't include my constructors in the code; they just initialize everything to 0.

    Blog text (30)
  • In object-oriented programming, a constructor is a method that creates new objects with specified properties.

  • You can define a constructor that takes parameters to initialize the object with custom values.

Surface Forms

constructor singular
constructors plural

Morphology

constructor = construct (semi-transparent) = construct + or

Formed by the same agentive suffixation, but the programming sense is a technical metaphor (a function that 'constructs' objects) and thus is a specialized extension.

Etymology

Constructor comes from Latin parts con- 'together' and struere 'to build', like the words construct and structure. So in programming a constructor is a special 'builder' function that sets up a new object with its first values.