1-1 Oop Concept

Embed Size (px)

Citation preview

  • 7/27/2019 1-1 Oop Concept

    1/17

    Introduction To OOP1.0

    Fundamentals Of JavaProgramming Language2.0

    Exception Handling3.0 Classes, Inheritance And

    Polymorphism4.0

    2012 | PN ROZITA SAAD1

  • 7/27/2019 1-1 Oop Concept

    2/17

    2

  • 7/27/2019 1-1 Oop Concept

    3/17

    Define OOP1

    Describe the History Of OOP

    2 List the Advantages Of Using OOP3

    Illustrate the Basic Terminologies Of OOP4 Distinguish between Abstraction &

    Encapsulation5 Differentiate between Structured

    Programming & OOP Approach6

    2012 | PN ROZITA SAAD3

  • 7/27/2019 1-1 Oop Concept

    4/17

    According to Wikipedia, Object Oriented Programming (OOP) is a programmingtechnique 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 datatypes and types of operations, which will be performed on the data structure.

    Example:

    Data data types

    Data Structu re Student No. Integer

    Mark float

    Types of o perat ion:Student No. :

    Sort student list based on

    Student No.

    Mark :

    Calculate mark.

    2012 | PN ROZITA SAAD4

  • 7/27/2019 1-1 Oop Concept

    5/17

    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 SAAD5

  • 7/27/2019 1-1 Oop Concept

    6/17

    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 PHDstudies 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 SAAD6

  • 7/27/2019 1-1 Oop Concept

    7/17

    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 SAAD7

  • 7/27/2019 1-1 Oop Concept

    8/17

    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 SAAD8

  • 7/27/2019 1-1 Oop Concept

    9/17

    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() candetermine exam result for object student.

    2012 | PN ROZITA SAAD9

    Object : Student

    Data : name, address, icno, sid, marks, status

    Method : DetermineStatus()

  • 7/27/2019 1-1 Oop Concept

    10/17

    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.

    2012 | PN ROZITA SAAD10

    class Student

    { String name, address, status;int icno, sid;

    double marks;

    char DetermineStatus()

    { if marks >= 40

    status = Pass;

    else

    status = Fail;

    }

    } Class

    Example 1 : Definition of Class Student

    data

    method

    Example 2 : Definition of Class Box

    class Box

    { double width, height, depth;

    double ComputeVolume()

    { return( width * height * depth ); }

    double ComputeArea()

    { return( width * height ); }

    }

    data

    method

    Class

  • 7/27/2019 1-1 Oop Concept

    11/17

    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.

    2012 | PN ROZITA SAAD11

    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.

  • 7/27/2019 1-1 Oop Concept

    12/17

    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.

    2012 | PN ROZITA SAAD12

    StudentObject

    AbstractionName, Student ID,

    Address, IC No

    Attribute

    Calculate_mark (),Determine_grsde (),

    Print_result ()

    Behaviors

    Student Class

    Figure Explain about abstraction

    concept

  • 7/27/2019 1-1 Oop Concept

    13/17

    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.

    2012 | PN ROZITA SAAD13

    Class A

    Class B

    Class C

    Base class to class B

    Derived class to class A

    Base class to C, D and E

    Derived class to class B

    Class EClass D

    Figure : Relationship between one class with

    another class. Derived class can be inherits

    characteristic from a base class.

  • 7/27/2019 1-1 Oop Concept

    14/17

    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.

    2012 | PN ROZITA SAAD14

    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)

  • 7/27/2019 1-1 Oop Concept

    15/17

    Abstraction Encapsulation

    Delete all unnecessary data and remainthe necessary data only

    control the access to data by hiding its

    information

    2012 | PN ROZITA SAAD15

  • 7/27/2019 1-1 Oop Concept

    16/17 2012 | PN ROZITA SAAD

    16

    Structured Programming Object Oriented Programming

    1 Based on programmer definition functionSplit a big program to several functions. Each

    function will perform the task more specific.

    Object Oriented Programming Technique

    The use of encapsulation concept

    combined data and function in one

    component ( class).

    2 Program code cannot be reused

    Each function assign to do specific task only.

    We must accept the function as it is. Tomodify 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 toinherits characteristic (function and data)

    other object.

  • 7/27/2019 1-1 Oop Concept

    17/17 2012 | PN ROZITA SAAD

    17

    3 Data manipulation function

    Data will be send to specific function to be

    manipulate where the function is notdetermine 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.

    4 No data control access.

    Main function will access all data and

    function in the program.

    Restriction in retrieving data.

    Access control exist for each data in the

    class.

    5 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.