Games
Problems
Go Pro!

Non Fundamental Properties

Reference > Science > Technology > Object Oriented Programming
 

On the previous page we walked through an example of how to create a sphere object, and discussed the fundamental properties of a sphere. We concluded that the fundamental properties of the sphere are radius and mass. We also concluded that properties like surface area, volume and density are NOT fundamental, because they can be calculated in terms of one or more of the fundamental properties, and that color is not a fundamental property because we add color to the sphere after it's created.

So what do we do with these non-fundamental properties?

Well, first it's important to understand that we shouldn't be able to set those values. For example, if we've told the computer to create a sphere with radius 2, and then we say to the computer, "By the way, the diameter of the sphere is 7," we've got a serious problem, because if the radius is 2, the diameter is 4 - that's just the way it is, and we shouldn't be allowed to tell the computer anything different!

So that's something we can't do with non-fundamental properties, but what should we do with them?

We should teach the computer how to calculate the values of those non-fundamental properties.

For example, here's a simple command to teach the computer how to calculate the sphere's diameter:

Sphere's diameter = Sphere's radius times two.

Now we can do the following:

COMMAND: Create a sphere with radius = 10, mass = 5, and call it S.
RESPONSE: Sphere S has been created.
COMMAND: Tell me the diameter of S.
RESPONSE: Radius of S is 20.

What happens in that last command? The computer uses what we taught it about spheres to figure out the diameter, and gives us the information.

We can do the same for the other properties:

Sphere's volume =
4
3
πr3 (we worked this out in the first page)
Sphere's density = The sphere's mass divided by the sphere's volume.

Now we can do this:

COMMAND: Create a sphere with radius = 10, mass = 5, and call it S.
RESPONSE: Sphere S has been created.
COMMAND: Tell me the density of S.
RESPONSE: The density of S is 0.0012.

So what really happened when we asked the computer for the density of the sphere? The computer tried to calculate the density, using our density rule we taught it, realized that it couldn't do that without first finding the volume, so it used our volume rule first, and then used that number in the density rule to give us an answer. And once we taught the computer all the rules, it all happened behind the scenes, and we didn't even have to worry about the nuts and bolts of it.

AND...(here's what's really wonderful about all this)...if we create a hundred different spheres, all with different radii and masses, every time we can say to the computer "Tell me this sphere's density," and the job is done, just like that!

But what about COLOR? That's a non-fundamental property of the sphere, too, and we haven't even talked about that! That's true. To set the color of the sphere we have to DO something to the sphere - we have to paint it. And if we are going to DO something to the sphere object, we need something called a METHOD. That's what we'll look at on the next page.

Questions

1.
Why shouldn't we try to tell the computer that what the volume of our sphere is?
2.
Suppose we were creating triangle objects; give two examples of non-fundamental property of a triangle object?
3.
What are some other non-fundamental properties of a sphere that we could consider?
4.
If we were creating objects of type "BOX," what non-fundamental properties might it have?
Assign this reference page
Click here to assign this reference page to your students.
Creating an Object - Basic AttributesCreating an Object - Basic Attributes
Methods - Changing an Object's PropertiesMethods - Changing an Object's Properties
 

Blogs on This Site

Reviews and book lists - books we love!
The site administrator fields questions from visitors.
Like us on Facebook to get updates about new resources
Home
Pro Membership
About
Privacy