Skip to main content
Lesson 1 - Introduction to Object Oriented Programming
ZIPPDF (letter)
Lesson MenuPreviousNext
  
Classes and Objects page 3 of 8

  1. Object-Oriented Programming (OOP) represents an attempt to make programs more closely model the way people think about and deal with the world. In object-oriented programming, a program consists of a collection of interacting objects. To write such a program you need to describe different types of objects: what they can do, how they are created, and how they interact with other objects.

  2. The world in which we live is filled with objects. For example, an object we are all familiar with is a drawing tool such as a pencil or pen. A drawing tool is an object, which can be described in terms of its state and behaviors. The attributes (state) of a pencil are its drawing color, width of the line it draws, its location on the drawing surface, etc. Its behaviors consist of drawing a circle, drawing a line in a forward or backward direction, changing its drawing direction, changing the color, etc.

  3. An object in programming is an abstraction for a real-world object. For example, a drawing tool is an attempt to model the attributes and behaviors of a pencil or pen.

    Figure 1.1 - A DrawingTool object named myPencil

  4. To create an object inside the computer program, we must provide a definition for objects - how they behave and what kinds of information they maintain is called a class. A class is a kind of mold or template that the computer uses to create objects.

  5. A class is like a rubber stamp that can be used many times to make many imprints. Each imprint is an object and each one has its own individual properties such as "size" and "position." Different stampings may have different characteristics, even though they were all made with the same rubber stamp.

    Figure 1.2 - A class and five instances having different values for instance variables "size" and "position".

  6. In OOP terminology, we say the DrawingTool object pencil is an instance of the DrawingTool class. An object can only be an instance of one class. In effect, an instance of the class belongs to the class.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.