12
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

Embed Size (px)

Citation preview

Page 1: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

By Patrick Lambert

Page 2: 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.

Page 3: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

There are two types of objects in the example below:

•Text boxes•Buttons

Page 4: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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.

Page 5: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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.

Page 6: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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;

Page 7: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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

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

Page 8: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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.

Page 9: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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.

Page 10: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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

x

t

Page 11: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

A uniform motion in two dimensions

x

y

Page 12: INTRODUCTION TO OBJECT ORIENTED PROGRAMMING By Patrick Lambert

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.