Skip to main content
Lesson 1 - Introduction to Object Oriented Programming
Lesson MenuPreviousNext
  
Objects in Software page 5 of 8

  1. A program is a collection of instructions that, when performed, cause a particular task to be performed on a computer. Individuals who write programs are therefore called programmers. The terms software and code refer to a collection of one or more programs, so programmers are also referred to as software developers.

  2. Today, the strategy most often employed by software developers is called object-oriented-programming (OOP). A programmer using an object-oriented strategy begins by selecting objects that can collectively solve the given problem.

  3. To illustrate how a particular program might be developed in an OOP fashion, the software developer begins with a set of program requirements that specifies the desired task for a program. For example:

    Write a program to draw a square on a piece of paper with a pencil.

  4. The program requirements suggest that there are two objects, namely a pencil and piece of paper. One way to determine the objects needed in a program is to search for the nouns of the problem. In our draw square problem, the pencil and paper are examples of such nouns.

  5. Once a programmer identifies the objects in the program, the next step is to find or create a class corresponding to each object. Classes are essential because they serve as the places where the code of an object oriented program resides.

  6. Ideally, a programmer reuses an existing class, as opposed to writing code for a new class. For the purposes of our drawing example, we will use the preexisting DrawingTool and SketchPad classes for the pencil and paper objects.

  7. Programming languages are like other foreign languages - the first exposure to a written example is bound to seem pretty mysterious. You don't have to understand the details of the program shown below, we'll go over them in the next lesson.

    Program 1.1 - DrawSquare.java

  8. The execution of an object-oriented program begins with an initial object. This initial object serves as the starting point for the entire program. For the program in Program 1.1, the initial object belongs to the DrawSquare class.

  9. The state of an object depends on its components (objects). The DrawSquare object includes one DrawingTool object declared in the line that begins with the word DrawingTool and a SketchPad object declared in the line that begins with SketchPad. The DrawingTool object is given the name pencil and the SketchPad object is given the name paper.

  10. An object's behavior is determined by instructions. When a program executes, the program's instructions are performed. There are nine instructions for the DrawSquare object that are found following the object declaration lines.

    1. The first instruction will construct a new SketchPad object named paper with dimensions of 300 by 300.
    2. The next instruction will cause a new DrawingTool object named pencil to be constructed on the SketchPad object named paper.
    3. The next line of code will cause the pencil to move forward 100 units drawing a line as it goes.
    4. The next line of code will cause the pencil to turn to the left 90 degrees.
    5. The remaining 5 steps repeat the process of steps c and d to draw the remaining three sides of the square.

  11. The DrawSquare example illustrates the tools that a programmer uses to write a program. A program is built from classes that a programmer writes or reuses. Classes are composed from instructions, and these instructions are used in such a way that they manipulate objects to perform the desired tasks.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.