Games
Problems
Go Pro!

Creating an Object - Basic Attributes

Reference > Science > Technology > Object Oriented Programming
 

Let'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.

Questions

1.
What did we use for the fundamental properties of a sphere?
2.
Can you think of one or more other properties of a sphere that was not mentioned here?
3.
Why isn't volume a fundamental property?
4.
Suppose we were creating triangles instead of spheres; what do you think the fundamental properties would be?
5.
Suppose we were creating a "BOX" object; what fundamental properties would it have?
Assign this reference page
Click here to assign this reference page to your students.
Introduction to Object Oriented ProgrammingIntroduction to Object Oriented Programming
Non Fundamental PropertiesNon Fundamental 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