Object Oriented Programming
description
Transcript of Object Oriented Programming
Object Oriented Programming
B.Sc. Multimedia ComputingMultimedia Authoring
Agenda
Procedural Programming v OOP Software Objects Classes and Methods The Object Oriented Paradigm
B.Sc. Multimedia ComputingMultimedia Authoring
Object Oriented Programming
Object-Oriented Programming is a way of describing
and structuring software systems that features objects
that contain functionality and data
Early program structure techniques kept program
functionality and data separate - so called
“procedural programming”
B.Sc. Multimedia ComputingMultimedia Authoring
Procedural Programming
10 readln(sum)
20 sum = sum + x
30 writeln(“The answer is” ), sum)
.
60 GOSUB 200
.
200 readln(answer)
.
300 return
B.Sc. Multimedia ComputingMultimedia Authoring
Object Oriented Programming
OOP places the data and functionality inside a software object - the data is siad to be encapsulated within the object
B.Sc. Multimedia ComputingMultimedia Authoring
Software objectdata and
functionality
Object Oriented Programming
Software objects communicate with other software objects to carry out the overall function of a software system by sending messages to each other
B.Sc. Multimedia ComputingMultimedia Authoring
Software object data and
functionality
Software object data and
functionality
Transport System
To model vehicles and drivers as an OOP software systemthink about the various objects, properties and functions of such asystem:
Vehicles - Type, Make, Model, Value, Registration Number
Drivers - Name, Age, Date of Birth, License Type
B.Sc. Multimedia ComputingMultimedia Authoring
Transport System: Vehicle
Object: VehiclesProperties (attributes)
TypeMakeModelValueRegistration Number
Functions (methods)
Create an object of type VehicleSet the Make of vehicleGet the make of vehilceSet the value of the vehicle
B.Sc. Multimedia ComputingMultimedia Authoring
Transport System: Driver
Object: Driver Properties (attributes)
NameDate of BirthLicense TypeValue
Functions (methods)
Create an object of type DriverSet the Name of a driverGet the name of a driverSet the type of licenseGet the type of license
B.Sc. Multimedia ComputingMultimedia Authoring
Driver Object
B.Sc. Multimedia ComputingMultimedia Authoring
Driver
Properties:
Name
Date of Birth
License Type
Set Name
Get Name
Set Date of Birth
Get Date of Birth
Functions (methods) to communicate with a Driver object
Vehicle Object
B.Sc. Multimedia ComputingMultimedia Authoring
Vehicle
Properties:
Make
Model
Registration No.
Value
Set Make
Get Make
Set Registration No.
Get Registration No.
Functions (methods) to communicate with a Vehicle object
Class Definition for a Vehicle
B.Sc. Multimedia ComputingMultimedia Authoring
public class Vehicle {
// ------ constructor------ //
public function Vehicle(){
} // end constructor
// ------ properties ------ //
var regNo:String;var make:String;var model:String;var saleValue:int;
Set Method Definition
B.Sc. Multimedia ComputingMultimedia Authoring
// ------- set the registration number ------- //
public function setRegNumber(aRegNumber:String):void {
this.regNo = aRegNumber;
} // end setRegNumber
Get Method Definition
B.Sc. Multimedia ComputingMultimedia Authoring
// -------- get the registration number ------ // public function getRegNumber():String {
var aRegNumber:String; aRegNumber = this.regNo; return aRegNumber;
} // end getRegNumber
Class Instantiation and Method References
B.Sc. Multimedia ComputingMultimedia Authoring
var aCar:Vehicle = new Vehicle();
var reg:String;var make:String;
aCar.setRegNumber("BKD 1");aCar.setMake("Ferrari");
make = aCar.getMake();reg = aCar.getRegNumber();
ActionScript 3.0 Implementation Details
B.Sc. Multimedia ComputingMultimedia Authoring
import uk.ac.uwe.multimedia.transport.Vehicle;
var aCar:Vehicle = new Vehicle();
var reg:String;var make:String;
aCar.setRegNumber("BKD 1");aCar.setMake("Ferrari");
make = aCar.getMake();reg = aCar.getRegNumber();
trace(make);trace(reg);
ActionScript 3.0 Implementation Details
B.Sc. Multimedia ComputingMultimedia Authoring
import uk.ac.uwe.multimedia.transport.Vehicle;
var aCar:Vehicle = new Vehicle();
var reg:String;var make:String;
aCar.setRegNumber("BKD 1");aCar.setMake("Ferrari");
make = aCar.getMake();reg = aCar.getRegNumber();
trace(make);trace(reg);
Object Oriented Programming Features
Classes are templates for objects, classes define properties and methods which dictate the state and behavior of the resulting software object
Data and related functions are contained within the same object space - encapsulation
Classes can be extended by creating subclasses which have similar properties and behaviors - inheritance
Inherited behaviors can be modified (overridden) to change the way an object responds to common messages- polymorphism
These three characteristics of OOP are often referred to as the “Object Oriented Paradigm”
B.Sc. Multimedia ComputingMultimedia Authoring