You are on page 1of 11

Object Oriented

Programming
OOPs the what is it and they why we use it
What is it not and why do we
need OOPs?
Let’s imagine we are going to write a program that will be a car
driving game.
We know we are going to need cars and that those cars will be
drawn on the screen.

What kind of things might be useful for our program to know


about each car in the game?
What is it not and why do we
need OOPs?
Properties

Make

Model

Colour

What would be good to know about Year


the cars in our game?
Price
What is it not and why do we
need OOPs?
Let’s imagine we are going to write a program that will be a car
driving game.
We know we are going to need cars and that those cars will be
drawn on the screen.

What kind of things might be useful for our cars to be able to do


in the game?
What is it not and why do we
need OOPs?
Methods

Start

Drive

Park
What would be good for our cars to
be able to do in our game? DisplayInfomation
What is it not and why do we
need OOPs?
How might that look in code?

String make = “Ford”;


String model = “Fiesta”;
String colour = RED;
int yOM= 1973;
float price = 8320.00;
printCarDetails();

void printCarDetails() {
System.out.println(“Make is “ + make);
System.out.println(“Model is “ + model);
System.out.println(“Colour is “ + colour);
System.out.println(“Manufactured in “ + yOM);
System.out.println(“Price : $“ + price);
}
What is it not and why do we
need OOPs?
• This works fine when we have one car but when we have
more than one cars and all our cars are different colours,
makes, models, prices and have different years of
manufacture we start to have a problem.

• How could we store all the information for the many cars in
our game?
What is it not and why do we
need OOPs?
Older procedural ways of coding:
• Hard to reuse code when things are slightly different
• Difficult to manage large amounts of data
• Don’t follow the way humans think about the world very well
• Encourage cutting and pasting of code and then making small
changes
OOPs
What Object Oriented
Programming allows us to do
is create a structure in code
that “knows” it’s properties
and can “do” it’s methods
Properties Methods

Make Start The design for each thing is


Model Drive called a class

Colour Park
Every time we make a new
Year DisplayInfomation version of the class it is called
an object
Price
What the car class might look
like.
public class Car {
// instance variables (what I know)
String make;
String model;
String colour;
int yOM;
float price;

// methods or things I can do


void printCarDetails() {
// some code missing here
}

void Start() {
// some code missing here
}

void Drive() {
// some code missing here
}

void Park() {
// some code missing here
}
}

You might also like