Home

ABCs of OOP Objects

Object Characteristics

OOP objects mimic (imitate) real world objects:

Like real world objects, OOP objects have three characteristics associated with them:

  1. PROPERTIES – innate (inborn; native) characteristics of an object that was given to it:

    1. from birth
    2. when it was created or manufactured
    3. when it was composited with other existing objects

      (Examples: external properties. (e.g., dimension (height, width), location (x, y), color). In an OOP programming language, properties are variables of an object.

  2. METHODS – what an object can do or what can be done to it. (e.g., hop, skip, jump, drive, park or reverse).  In an OOP programming language, methods are functions of an object.

  3. EVENTS – what trigger an object to do something (e.g., if you pinch a person, he may jump, if you put a key in a car ignition and turn it, the car may start.).  In an OOP programming language, events are special functions of an object that makes them work.
Close

A variable is a container that is assigned to a SINGLE type of data (e.g., firstName = "John").

Close

A function is a container that returns a calculation of numbers (or concatenation of strings) or performs a series of tasks. It can be thought of as a calculator that returns a value or a to do list that get completed. A function can tell an object how it should "function."

NOTE: These characteristics are typically written programmatically using the dot syntax. In PHP, the dot is replaced with "->" symbols.

  1. Object.property
  2. Object.method ( )
  3. Object.event ( )

    NOTE: Since methods and events are both functions, they will have a set of parenthesis at the end. Property usually does not have parenthesis.

For example, you typically define an object to have properties and one or more methods:

var person =
 {
   firstName : "Bob",
   lastName : "Jones",
   age : "53",
   fullName : function(e) { return this.firstName + " " + this.lastName;}
 };

alert(person.fullName); // Returns "Bob Jones"

NOTE: The properties were placed on a single line so that you can see the explaination that will be explained below better. Normally, they would be written on several lines.

While both properties and methods are both ASSOCIATED with an object, properties are associated with the variables part of the object (in the example above, firstName, lastName and age) and methods are associated with the functions part of an object. However, without attempting to confuse the matter, ALL of of them (e.g., firstName, lastName, age and fullName) are in reality properties of that object because they are on the left side of the colons (:) which denotes properties and their corresponding values which is usually stated as name/value pairs.

< Previous Topic     Next Topic >

© 2015. RMCS. All rights reserved.