Is Constructor a Method?
in
Programming Questions
•
1 year ago
I am just another designer getting up to speed with computing, and here is another question I need to know for the sake of advancing further.
Considering a super-simple class:
class Simple {
// param
float x, y;
color c;
float d;
// ctor
Simple(float tempX, float tempY, color tempC, float tempD) {
x = tempX;
y = tempY;
c = tempC;
d = tempD;
}
// methods
void setMe() {}
void move() {}
void update() {}
}
Main Question:
I noticed that in many cases, I do not need a constructor at all (blank ctor), since I can "construct" an object from a method (i.e. setMe() ). Can I assume that constructors are a kind of in-built overloaded methods to "construct" any first instance of a class?
void setMe(float tempX, float tempY, color tempC, float tempD) {
x = tempX;
y = tempY;
c = tempC;
d = tempD;
}
A Bonus Question:
I don't mean to sound like Neo (the Matrix) but "Is everything a method afterall?" I mean, looking at programming in a naive way of mine, everything looks more or less a class, say a so-called library is a class composed of many pre-built functions and methods, and so is the Processing IDE I am using. Can I look at it that way?
Many thanks in advance,
Considering a super-simple class:
class Simple {
// param
float x, y;
color c;
float d;
// ctor
Simple(float tempX, float tempY, color tempC, float tempD) {
x = tempX;
y = tempY;
c = tempC;
d = tempD;
}
// methods
void setMe() {}
void move() {}
void update() {}
}
Main Question:
I noticed that in many cases, I do not need a constructor at all (blank ctor), since I can "construct" an object from a method (i.e. setMe() ). Can I assume that constructors are a kind of in-built overloaded methods to "construct" any first instance of a class?
void setMe(float tempX, float tempY, color tempC, float tempD) {
x = tempX;
y = tempY;
c = tempC;
d = tempD;
}
A Bonus Question:
I don't mean to sound like Neo (the Matrix) but "Is everything a method afterall?" I mean, looking at programming in a naive way of mine, everything looks more or less a class, say a so-called library is a class composed of many pre-built functions and methods, and so is the Processing IDE I am using. Can I look at it that way?
Many thanks in advance,
1