I’m an old-school programmer. I don’t like OOP. It complicates shite unnecessarily with terminology and too much syntax.
A constructor is just a function/procedure that creates/builds/initialises a particular object.
If you have an object that represents, say, a display screen, the constructor would likely do things like:
– Allocate a screen buffer
– Initialise variables (properties/members of the object, etc.) like screen height, width, colour depth, etc.
– Initialise the graphics subsystems needed, etc.
It’s just the piece you call to “create” an object of that type, which in many languages happens automatically if you say “var this_display = new DisplayScreen” or whatever. When you do that, the constructor is automatically run, to initialise that new object you just created.
A constructor is nothing more than a function that builds an object, and an object is just a fancy concept given to a self-contained structure that has all its required variables and functions put together in one convenient place.
Latest Answers