Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

CSC186 OBJECT ORIENTED PROGRAMMING

CSC186 OBJECT ORIENTED PROGRAMMING| edited from JUHAIDA ISMAIL 1


LESSON OUTCOMES
Upon completion of this chapter, students should be able to:

▪ Understand the concept of object-oriented programming


approach
▪ Explain the similarities and differences of structured
programming and object-oriented programming approach

CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL 2


OBJECT ORIENTED PROGRAMMING

▪ Is a programming approach that focuses on using data(OBJECTS)


to design and build applications.
▪ For example : Bank – customer, money, account

▪ 4 basic concepts :
✓ polymorphism
✓ inheritance
✓ encapsulation
✓ abstraction

▪ Other important concepts


✓ classes
✓ objects

CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL


OBJECT ORIENTED PROGRAMMING

CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL 4


OBJECT ORIENTED PROGRAMMING
CHARACTERISTICS of Object Oriented Programming:

▪ It gives importance to data (object) rather than


procedure (process)
▪ Programs are divided into objects
▪ Data is hidden
▪ Objects may communicate with each other
▪ New data and function can be easily added
▪ Employ bottom‐up approach
✓ in OOP , you first write a base class, and constantly
derive new child classes from the existing one (like
car class will probably derive from a class called
vehicle)

CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL 5


OBJECT ORIENTED PROGRAMMING
CHARACTERISTICS of Object Oriented Programming:

6
OBJECT ORIENTED PROGRAMMING
ADVANTAGES of Object Oriented Programming:

▪ Avoid redundancy in code and use existing


class (reusability).

▪ Save time and high productivity

▪ Secure program codes

▪ Easy to partition the work based on objects

▪ Easy to upgrade from smaller to larger system

▪ Software complexity can be managed

CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL 7


OBJECT ORIENTED STRUCTURED
# STRUCTURED OBJECT ORIENTED
1 Focuses on process Focuses on data

2 Using top-down approach Using bottom up approach


3 Programs are divided into small self Programs are divided into small
contained functions entities called objects
4 Less secure as there is no way of More secure since it has data hiding
data hiding features
5 Can solve moderately complex Can solve any complex programs
programs
6 Less reusability, more function More reusability, less function
depency dependency
7 Less abstraction, less flexibility More abstraction, more flexibility.

8
Sample of Structured Programming
(using C++ programming language)
#include <iostream> double calcSalaryInYear(double salPerMonth)
double calcSalaryInYear(double); {
void display(String,String,double,double); double salInYear=salPerMonth*12;
int main()
return salInYear;
{
}
String name, icNumber;
double salaryPerMonth, salaryInYear; void display(String name,String icNumber,double
salaryPerMonth,double salaryInYear)
cout<<"Enter name:"; { cout<<"Name:“<<name;
cin>>name; cout<<"IC Number:“<<icNumber;
cout<<"Enter IC number:"; cout<<"Salary Per Month:“<<salaryPerMonth;
cin>>icNumber;
cout<<"Salary In Year:“<<salaryInYear;
cout<<"Enter salary per month:";
cin>>salaryPerMonth; }
}
salaryInYear=calcSalaryInYear(salaryPerMonth);
display(name,icNumber,salaryPerMonth,salaryInYear);
return 0;
}

Edited from Object Oriented Programming Module(Zamlina Abdullah,Zainab Othman,Nurbaity Sabri, Zawawi Ismail, Khairunnisa Abdul
Kadir,2020)
Sample of Object Oriented Programming
(using java programming language)
public class employee public void display()
{ {
private String name; System.out.println("Name:"+name);
private String ICNumber; System.out.println("IC Number:"+ICNumber);
private double salaryPerMonth; System.out.println("Salary Per
Month:"+salaryPerMonth);
//constructor System.out.println("Salary In
public employee(String nm,String IC,double Year:"+calcSalaryInYear());
salPerMonth) }
{ name=nm; }
ICNumber=IC;
salaryPerMonth=salPerMonth;
}

//example of method
public double calcSalaryInYear()
{ double salInYear=salaryPerMonth*12;
return salInYear;
}

Edited from Object Oriented Programming Module(Zamlina Abdullah,Zainab Othman,Nurbaity Sabri, Zawawi Ismail, Khairunnisa Abdul
Kadir,2020)
Sample of Object Oriented Programming
(using java programming language)-cont
import java.util.Scanner; employee emp=new
public class empAppOOP employee(name,ICNum,salPerMth);
{
public static void main(String args[])
{ salaryInYear=emp.calcSalaryInYear();
Scanner inputText=new Scanner(System.in); emp.display();
Scanner input=new Scanner(System.in); }
}
String name,ICNum;
double salPerMth,salaryInYear;

System.out.println("Enter name:");
name=inputText.nextLine();
System.out.println("Enter IC number:");
ICNum=inputText.next();
System.out.println("Enter salary per
month:");
salPerMth=input.nextDouble();

Edited from Object Oriented Programming Module(Zamlina Abdullah,Zainab Othman,Nurbaity Sabri, Zawawi Ismail, Khairunnisa Abdul
Kadir,2020)
THANK YOU
CSC186 OBJECT ORIENTED PROGRAMMING| JUHAIDA ISMAIL 12

You might also like