Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Objects Kevin Harville.

Similar presentations


Presentation on theme: "Using Objects Kevin Harville."— Presentation transcript:

1 Using Objects Kevin Harville

2 Object-oriented programming
Object-oriented programming was specifically created to allow programmers to deal with programming in a real-world manner Some languages such as JavaScript and Visual Basic are sometimes referred to as object-based. In true object-oriented languages everything is an object.

3 Objects In the real world, objects are nouns.
In the computer world, objects are nouns. Examples: window, document, forms, buttons, links.

4 Objects In the real world, there are abstract nouns.
In the computer world, some objects are abstract. Examples: history, Date, Math

5 Objects are instances of a blueprint, or "class".
For instance, the computer has a blueprint of what Date objects can do. We can use this blueprint for our own objects. myDate = new Date() Just like we all have names, each object has a specific name or subscript making it uniquely identifyable. Occasionally we simply use the master object, such as when we use Math methods and properties.

6 Objects may have pieces
Pieces of objects are known as "child" objects. Inversely, the object comprised of child objects is the "parent". In the following example, myForm and myButton are children of the parent document. document.myForm.myButton.value = 7 A real life comparison: bike.frontWheel.radius = 14

7 Object Methods In the real world, objects do things.
In the computer world, objects do things. We call these "methods" : Ex: window.close() Methods are simply functions of objects!

8 Methods Functions may return values.
Methods are functions of an object. Methods may therefore return a value. myAnswer = Math.round( 6.5) reduces to: myAnswer = 7

9 Objects We define the specifics of our actions (methods) with arguments, also called parameters. document.write("Hello"); yourBD = new date(0, 14, 1978); Zero! Zero is January, the zeroeth month!

10 Objects Objects have properties Car.weight = 7200 Car.color = "blue"
Properties are simply object variables. We can use a property whereever we want to indicate a value. document.write( Car.weight );

11 Identifying objects If it is anything on the left hand side of the dot (or any thing), it is an object: document.myForm.myButton.value = "button"; On the right side is either a property or a method.

12 Telling methods from properties
Methods do something, properties describe something. If it has arguments or empty parenthesis, it is a method. If it is simply a value that could be set or read, it is a property. If it is a value that would be calculated, then returned, it is a method.

13


Download ppt "Using Objects Kevin Harville."

Similar presentations


Ads by Google