Vous êtes sur la page 1sur 17

1.0 2.

0
3.0 4.0
2012 | PN ROZITA SAAD

Introduction To OOP Fundamentals Of Java Programming Language Exception Handling Classes, Inheritance And Polymorphism
1

1 2

Define OOP Describe the History Of OOP List the Advantages Of Using OOP

3
4

Illustrate the Basic Terminologies Of OOP


Distinguish between Abstraction & Encapsulation Differentiate between Structured Programming & OOP Approach
3

5
6
2012 | PN ROZITA SAAD

According to Wikipedia, Object Oriented Programming (OOP) is a programming technique that uses objects to design the applications and computer programs.

It also can be define as a type of programming where the programmer can define data

types and types of operations, which will be performed on the data structure. Example: Data Structure Data Student No. Mark data types Integer

float
Types of operation: Student No. : Sort student list based on Student No. Mark : Calculate mark.

2012 | PN ROZITA SAAD

By using this method, data structure will become an object such as Student object, which consists of data and functions. The programmer can create relationship between one object with another object such as an object inherits characteristics from another object

Object-oriented programming is a method used to write programs where data and behaviours are packaged together in one class. Object is a member of a class.

2012 | PN ROZITA SAAD

In the 1960s, Simula language were developed by Norwegian Computing Center.


It became the first OOP language which applies the OOP concepts. It was designed for the purpose of creating simulations, and was developed by Kristen Nygaard and Ole-Johan Dahl in Norway.

In the 1970s, Alan Kay developed Smalltalk language at Xerox Parc (Palo Alto Research Center).
Targeted to be understandable to people with no prior training in computer use. Demonstrated by experiments conducted using children as programmers

In the 1980s, Bjarne Stroustrup at Bell Lab who had learned Simula during his PHD studies develop C++ as an extension of C. Later many other OOP languages were developed: Eiffel, Objective-C, Actor,Object Pascal and etc.

2012 | PN ROZITA SAAD

Code extensibility / kod boleh ditambah


Ability to add codes, which are already existing and consistent with needs.

Code reusability / kod boleh diguna berulangkali


Existing code can be tested first before it is inherited from previous module.

This will save cost and time needed to develop software.


With this method, it will help to increase programmers productivity.

2012 | PN ROZITA SAAD

Represent real world / menggambarkan dunia sebenar


Using object-oriented concept, it will assist the programmer in creating a module because

data used represents real situations.

Data security / keselamatan data

The use of encapsulation concept has made data to be protected from misuse by an unauthorized person.

2012 | PN ROZITA SAAD

1. Object
Object is the term used to explain many things.

Example: student, chair and circle. An Object consists of data and method Properties of an object are called data. In the real world, characteristics of an object can be divided into two types: Data that can be seen such as a human with two hands. Data that cannot be seen such as a human with a name. Method is a set of function that manipulates data, such as method DetermineStatus() can determine exam result for object student.

Object : Student Data : name, address, icno, sid, marks, status Method : DetermineStatus()

2012 | PN ROZITA SAAD

2. Class
A set of objects that have similar attributes(characteristics, which can be seen.) and methods. Attributes and methods of a class can be used by each object from that class.

class Student { String name, address, status; int icno, sid; double marks;
char DetermineStatus() { if marks >= 40 status = Pass; else status = Fail; } } Class

data method

class Box { double width, height, depth; double ComputeVolume() { return( width * height * depth ); } double ComputeArea() { return( width * height ); }

data

method
} Class

Example 2 : Definition of Class Box Example 1 : Definition of Class Student

2012 | PN ROZITA SAAD

10

3. Encapsulation
Encapsulation is a process of tying together all data and methods that form a class and

control the access to data by hiding its information. It enables access to object just by using methods of that object. It is one of the security features in object-oriented programming (OOP).
Attributes and methods of a class can be used by each object from that class.
Class Student Name, Student ID, Address, IC No

Calculate_result() Determine_grade() Print_result() Figure above Explains the concept of encapsulation in OOP for class Student

Based from the example given, data and methods are combined in one class. If the college management wants to get the status whether a student pass or fail, they only have to know the status without knowing how to determine or calculate the grade. So, this is a way of implementing encapsulation where the code in the program is hidden thus to prevent from being modified. 2012 | PN ROZITA SAAD 11

4. Data Abstraction
Data abstraction is a process to delete all unnecessary attributes and remain the necessary

attributes to describe an object Attributes and methods of a class can be used by each object from that class.

Student Object Abstraction

Student Class Attribute Name, Student ID, Address, IC No

Behaviors Calculate_mark (), Determine_grsde (), Print_result ()

Figure Explain about abstraction concept


2012 | PN ROZITA SAAD 12

5. Inheritance
Create a new class from an existing class together with new attributes and behaviours. The new class will have the same ability as the base class. Use the concept of code reusability.
Class A Base class to class B

Class B

Derived class to class A Base class to C, D and E

Class C

Class D

Class E

Derived class to class B

Figure : Relationship between one class with another class. Derived class can be inherits characteristic from a base class.
2012 | PN ROZITA SAAD 13

6. Polymorphism
Polymorphism is a process of giving the same message to two or more different objects and

produce different behaviours depending on how the objects receive the message.
It is said to be One interface, many methods.

Example 1:
Message: Withdraw a money from bank
Action Object Student1 : Using ATM machine from Bank account. Student2 : Using ATM Machine from other Bank (MEPS)

2012 | PN ROZITA SAAD

14

Abstraction
Delete all unnecessary data and remain the necessary data only

Encapsulation
control the access to data by hiding its information

2012 | PN ROZITA SAAD

15

Structured Programming Based on programmer definition function 1 function will perform the task more specific.

Object Oriented Programming Object Oriented Programming Technique combined data and function in one component ( class).

Split a big program to several functions. Each The use of encapsulation concept

Program code cannot be reused Each function assign to do specific task only. We must accept the function as it is. To modify it, the code need to copy and modify it based on it requirement

Allowed code reusability It can be done through inheritance technique. This technique allowed object to inherits characteristic (function and data) other object.

2012 | PN ROZITA SAAD

16

Data manipulation function Data will be send to specific function to be manipulate where the function is not determine first.

Using encapsulation to react on data Encapsulation is used to package data with function that will take an action over the data. It define which function will be perform to each object. Class will control any operation done to data and function inside it. Restriction in retrieving data. Access control exist for each data in the class.

No data control access. Main function will access all data and function in the program.

Not supported polymorphism Each data must be declared before do any operation on it.

Used polymorphism Allowed one function to be executed with various method.

2012 | PN ROZITA SAAD

17

Vous aimerez peut-être aussi