Creating an Object - Basic Attributes
Reference > Science > Technology > Object Oriented ProgrammingLet's return to our sphere example from the previous page. When we are planning to teach our computer about a certain type of object, we need to think very carefully about what are the fundamental things that make the object what it is. Because every time we ask the computer to create an object of a particular type, we ought to tell it all the fundamental properties of that object.
So what are the fundamental properties of a sphere? And what, exactly, do I mean by "fundamental?" Well, let's start by imagining a sphere, and make a list of all of its properties. Ready? Here's a list:
Radius
Diameter
Surface Area
Volume
Mass
Density
Color
You might be able to think of some other properties that a sphere could have, but that's a pretty good list to start with. Now the question is: which of these are "fundamental" properties? Essentially what I mean by fundamental is, it doesn't depend on any other property, and it's a necessary piece of information required to create the sphere.
For example, surface area is not fundamental, because it depends on the radius. Likewise, volume is not fundamental.
Density is not fundamental - why not? Because it depends on the mass and the volume. Which really means it depends on the mass and the radius, since the volume depends on the radius.
Color doesn't depend on any of the other properties, so maybe it's fundamental. On the other hand, you could argue that color is something that's added to the sphere AFTER it's been created, and should not be considered fundamental. We'll say it's not fundamental.
Mass doesn't depend on any of the other properties, so it's also fundamental.
What about radius and diameter? You could argue that diameter depends on radius, but you could also argue that radius depends on diameter! So we'll need to call one of them a "fundamental" property - but not both. Does it matter which we call fundamental? Maybe not - but as I think about it, I remember that my surface area and volume formulas are in terms of r (radius) instead of d (diameter), so it makes more sense to call radius a fundamental property.
So from our list, two of those properties are fundamental: radius and mass.
So whenever we tell the computer to create a virtual sphere, we should pass both of those pieces of information to the computer, so it knows everything there is to know about the sphere.
COMMAND: Create a sphere object with radius = 2; mass = 10. Call the sphere S.
RESPONSE: Sphere S has been created!
On the next page we'll explore what to do with non-fundamental properties.