Home
Examples
Labs
Assignment
Marks
Midterm
Final Exam
Resources

Object Oriented Programming

Object oriented programming is meant to model the way that the real world works.  In the real world, you don't do every task yourself, you often ask other people to do things for you.  You find people with special skills and ask them to do the things that they are good at.  You ask a dentist to check your teeth, and you ask a mechanic to check your car.  If you asked a mechanic to check your teeth he would tell you that he doesn't know how to do that.
  • class - the type of an object, or the category that it belongs to; objects that belong to the same class have the same behaviour.
  • object - a particular instance of a class, an actual example that exists.
  • state - the properties or attributes of an object; the information that the object has to remember about itself.
  • behaviour - the methods of an object; the things that the object knows how to do.
  • message passing - communication with objects; we ask an object to do something by sending it a message, the message invokes a method (one of the object's behaviours).
  • arguments - any extra information passed along with the message; this is any information that the object will need in order to do whatever you asked it to do.
  • return - the value given back as a result of whatever you asked the object to do; note that methods do not always return something.

For Example : class Person

  • You are a person object.  You are a particular example of the class person.


  • You have attributes like a particular name, gender, height and weight.  The value of these attributes describes your state.


  • All other person objects have attributes like name, gender, height and weight, but the value of their attributes may be different than yours.  Every person object taking cmpt111 has a name, but no one has the same name.  Every person object taking cmpt111 also has a height.  Some people have the same height, but many people are shorter or taller than others.


  • When objects belong to the same class they have the same behaviour - they know how to do the same things.  For example, all person objects know how to blink their eyes.


  • If I want a particular person object to blink their eyes I have to ask them to do it.  In java, we send a message to the particular person object that we want to blink.  If I wanted Emmett to blink his eyes twice I would say: Emmett.blinkEyes(2);.  However, if I wanted Debbie to blink her eyes just once I would say: Debbie.blinkEyes(1);.


  • The blinkEyes method of the person class requires the arguement "number of times to blink", and it doesn't return anything.