Objects
Objects
-
OOP is based around the concept of objects. Objects are little black boxes
of functionality that are fully independent of any code that references
or uses them.
-
Objects can be thought of as exhibiting two characteristics. Objects have
properties and objects have methods.
-
Properties describe the qualities of an object while methods specify the
object's behavior.
-
The typical "introduction to objects" chapter will give you an example
something like this:
The Cat Object |
Properties |
Methods |
Eye Color |
Can Purr |
Number of legs |
Catches mice |
Species |
Rips up the couch |
Although this is not a perfect analogy, sometimes
when I am trying to figure out what an object looks like, I think of objects
in terms of nouns, properties in terms of adjectives, and methods in terms
of verbs. |
-
However, let's consider a more realistic object that you might have to
deal with in your code. let's consider the HTML FORM
"Select Box" object that we discussed
on Day One and which is shown below as a reminder:
If you recall, a Select Box object has several properties.
For one, Select Boxes have a SIZE that corresponds to the number of visible
selections. Select Boxes also can be set to allow either multiple or single
selections. Finally, Select Boxes have a list of OPTIONS that are tied
to an administratively-defined NAME.
Meanwhile, Select Boxes have methods.
For example, a select box knows how to create its popup list when a user
clicks on the down arrow. Also, if a user selects an item from the popup
list, the select box knows how to select that item. Further, the Select
Box knows how to close the popup box when a user selects an item.
The table below presents a quick reference to our select box object.
The Select Box Object |
Properties |
Methods |
Size |
Open Drop Down Box |
Selection Policy |
Select an Item |
List of Items |
Close Drop Down Box |
Object-Oriented
Programming
Table of Contents
Encapsulation
|