Skip to main content
ICT
Lesson A1 - Introduction to Object Oriented Programming (OOP)
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

C. Objects in Software page 5 of 8

  1. A program is a collection of instructions that performs a particular task on a computer. Software is a collection of one or more programs. Code refers to the actual symbols that a programmer types in that tell the computer what instructions to execute. Individuals who write programs are called programmers, software-engineers, software-architects, and coders among many other terms.

  2. OOP is a strategy often employed by software developers. A programmer using an OOP strategy begins by selecting objects that can collectively solve the given problem.

  3. To develop a particular program in an OOP fashion, the software developer might begin with a set of program requirements. For example:

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

  4. A way to determine the objects needed in a program is to search for the nouns of the problem. This technique suggests that the above program should have three objects: a pencil, a piece of paper, and a square.

  5. Ideally, a programmer reuses an existing class to create objects, 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. However, we don’t have a class for a square that is pre-made, so we must make our own.

  6. Programming languages can be compared to a foreign language - 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. They will be covered in more detail in the next lesson.

Code Sample 1.1 - DrawSquare.java

  1. In OOP, we concern ourselves mostly with the objects themselves and how they relate to the other objects in the program. However, there must be a starting point for the program to begin creating objects, as the objects would obviously not be able to do anything if they did not exist. Code Sample 1.1 has no starting point and would therefore not be able to do anything by itself. Later on, we will learn how to utilize this code in an actual program.

  2. The state of an object depends on its components. 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 myPencil and the SketchPad object is given the name myPaper.

  3. A constructor is a method with the same name as the class. The first instruction will construct a new SketchPad object named myPaper with dimensions of 300 x 300 (read as 300 by 300). The next instruction will cause a new DrawingTool object named myPencil to be constructed using the SketchPad object named myPaper.

  4. An object’s behavior is determined by instructions within its methods. When the method draw() for a DrawSquare() object is called, the instructions within the draw method will execute in the order they appear. There are seven instructions in the draw method. The first instruction will cause the myPencil to move forward 100 units drawing a line as it goes. The next line tells myPencil to turn left. The remaining 5 steps repeat the process of steps to draw the remaining three sides of the square.

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

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.