INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

Preview:

Citation preview

INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

By Patrick Lambert

An object oriented program (OOP) is basically a program that has different objects that do different jobs.

There are two types of objects in the example below:

•Text boxes•Buttons

An object can be duplicated a little differently to reuse the basic function.

Namely, these objects inherit characteristics from other objects called ancestors or parents.

Here is an example program that calculated both uniform motion in one and two dimensions.

The one dimensional part was the ancestor/ parent object, and the two dimensional part was the child object.

For example, the one dimensional part of the program declares the variables that are below.

x00= x0;delta= dt;vx= vx0;time= ttot;steps= ttot/delta;

The two dimensional part of the program declares the variables that are below.

x00= x0;delta= dt;vx= vx0;time= ttot;y00= y0vy=vy0

Back to the jobs of the program.

To show that the different parts of the program have different jobs , here are some examples.

uniform motion one dimensional program:

...tt=0.0;for(i =1; i<= steps; i++){xx=x(tt);                      fprintf(pf,"%f %f\n", tt,xx);tt= tt + delt;} fclose(pf);...

To get xx for our plot, the uniform motion in the x direction at a time tt. The uniform motion in the x direction is x=x0+t*v.

uniform motion two dimensional program:

...tt=0.0;for(i =1; i<= steps; i++){xx = x(tt); yy = y(tt); fprintf(pf,"%f  %f\n",yy,xx); tt = tt + delt;} fclose(pf);...

To get yy for our plot, the uniform motion in the y direction at a time tt. The uniform motion in the y direction is y=y0+t*v.

The displacement for a uniform one dimensional motion with respect to time

x

t

A uniform motion in two dimensions

x

y

Summary:

OOP is easier to look at. If you have an error it would be easy to find.

OOP is easy to add or take something away.

For example, if I took away the uniform motion two dimensional part of the program it would not affect the

uniform motion of the one dimensional part.

Recommended