+ All Categories
Home > Documents > 1568778_634861630098116250

1568778_634861630098116250

Date post: 03-Apr-2018
Category:
Upload: sasirekha-perumalvijayan
View: 213 times
Download: 0 times
Share this document with a friend

of 23

Transcript
  • 7/29/2019 1568778_634861630098116250

    1/23

    OBJECT ORIENTED CONCEPTS

    By ARIF

  • 7/29/2019 1568778_634861630098116250

    2/23

    DEFINITIONOF OOP

    The object oriented programming (OOP) is a

    programming model where Programs are organized

    around object and data rather than action and logic.

    OOP allow decomposition of a problem into a number of

    entities called Object and then builds data and function

    around these objects.

  • 7/29/2019 1568778_634861630098116250

    3/23

    OOPS CONCEPTS

    1. Classes

    2. Objects

    3. Encapsulation

    4. Abstraction5. Inheritance

    6. Polymorphism

    We will consider an example to understand all

    the above OOPs Concepts

  • 7/29/2019 1568778_634861630098116250

    4/23

    EXAMPLE :

    Consider a Banking System in which customers

    are allowed to have different types of bank

    accounts(such as saving , current and fixed

    deposit) in any branch of the bank.

    Customers can perform operations such as deposit

    money, withdraw money and transfermoney

    between accounts with the help of functions

    provided by the system such as showbalance,

    updatebalance and calculateinterest.

  • 7/29/2019 1568778_634861630098116250

    5/23

    OOPS CONCEPT 1: CLASSES

    A class is a user defined data type with a template that

    serves to define its properties.

    or

    Class is a blueprint of an object that contains variablesfor storing data and functions to performing operations on

    these data.

    The entire set of data and code of an object can be madea user-defined data type with the help of a class. In fact,

    objects are variables of type class.

    Class will not occupy any memory space and hence it is

    only logical representation of data.

  • 7/29/2019 1568778_634861630098116250

    6/23

    OOPS CONCEPT 2: OBJECTS

    Object is an instance ofa class

    An object contains both data and methods that

    manipulate that data.

    The data represent the state of the object Data can also describe the relationships

    between objects.

    Example: A Saving Account might have

    A balance (the internal state of the account) An owner (some object representing a person)

  • 7/29/2019 1568778_634861630098116250

    7/23

    CLASSESAND OBJECTS [CONT..]

    Class SavingAccount

    Account_number

    Balance

    Owner

    Branch

    Account_number 101

    Balance 1000

    Owner abc

    Branch b1

    Account_number 102

    Balance 20,000

    Owner xyz

    Branch b1

    Operations

    ShowBalance

    updateBalance

    CalculateInterest

    CLASS

    Object

  • 7/29/2019 1568778_634861630098116250

    8/23

    OOPS CONCEPT 3: ENCAPSULATION

    Wrapping up data member and method together into a

    single unit (i.e. Class) is called Encapsulation.

    Encapsulation provides the ability to hide internaldetails of an object from its users and other object.

    The outside user may not be able to change the

    state of an object directly. However state of an

    object can be altered indirectly in various languagessuch as C# using accessorand mutatormethods

  • 7/29/2019 1568778_634861630098116250

    9/23

    ENCAPSULATION [CONT..]

    Class BankAccount

    Private: Account_number

    Private: Balance

    Private: OwnerPrivate: Branch

    Public: ShowBalance

    Public: UpdateBalance

    Public: calculateInterest

  • 7/29/2019 1568778_634861630098116250

    10/23

    OOPS CONCEPT 4: ABSTRACTION

    Abstraction is the act of representing the essential features without

    including the background details.

    lets you focus on what the object does instead of how it doesit.

    provides you a generalized view of your classes or object byproviding relevant information.

    Classes use the concept of abstraction and aredefined as a list of abstract attributes such as size,weight and cost, and functions to operate on these

    attributes. They encapsulate all the essentialproperties of the objects that are to be created.Since the classes use the concept of dataabstraction, they are known as Abstract Data Types(ADT).

  • 7/29/2019 1568778_634861630098116250

    11/23

    ABSTRACTION [CONT..]

    Suppose you have 2 account types namely

    Saving account(accountno, owner, balance, interest)

    Fixed deposit account(accountno, owner, balance, interest,

    year)

    Abstract information (Necessary and Common

    Information) for the object Bank Account" is

    balance and account no.So, for Bank Account we will have Abstract Class as

    follows:

  • 7/29/2019 1568778_634861630098116250

    12/23

    ABSTRACTION [CONT..]

    BankAccount

    Account_number

    Balance

    Owner

    Branch

    ShowBalanceAbstract:calculateInterest

    Saving Account

    Account_number

    Balance

    OwnerBranch

    ShowBalance

    Calculate Interest

    Fixed Deposit

    Account

    Account_number

    BalanceOwner

    Branch

    ShowBalance

    Calculate Interest

    Abstract class

    calculateInterest having

    different implementation

  • 7/29/2019 1568778_634861630098116250

    13/23

    OOPS CONCEPT 5: INHERITANCE

    Inheritance is the capability of one class to inherit

    properties from other class.

    It supports the concept of hierarchical classification.

    Inheritance is process of object reusability. Enables objects to inherit attributes and behaviors

    from other objects, thereby reducing the amount of

    new code that must be designed, written, and

    tested each time a new program is developed.

    Any changes made in the parent class, are

    inherently observed in the subclasses.

  • 7/29/2019 1568778_634861630098116250

    14/23

    INHERITANCE [CONT..]

    1. Single Inheritance

    2. Multi-Level Inheritance

    Class A

    Class B

    Class A

    Class B

    Class C

  • 7/29/2019 1568778_634861630098116250

    15/23

    INHERITANCE [CONT..]

    3. Hierarchical Inheritance

    4. Multiple Inheritance

    Class A

    Class B Class C

    Class A Class B

    Class C

  • 7/29/2019 1568778_634861630098116250

    16/23

    INHERITANCE [CONT..]

    5. Multi-path/Hybrid Inheritance

    Class A

    Class B Class C

    Class D

  • 7/29/2019 1568778_634861630098116250

    17/23

    INHERITANCE [CONT..]

    Current Account

    Fixed Deposit Account

    Savings Account

    Bank Account

  • 7/29/2019 1568778_634861630098116250

    18/23

    INHERITANCE [CONT..]

  • 7/29/2019 1568778_634861630098116250

    19/23

    OOPS CONCEPT 6: POLYMORPHISM

    Polymorphism means one name many forms.

    Essentially, Polymorphism is the capability of oneobject to behaves in multiple ways.

    In OOP, it is a language's ability to handle objects

    differently based on their runtime type and use. For example:

    An operation may exhibit different behavior in differentinstances. The behavior depends upon the types of dataused in the operation. For example, consider the operation of addition. For two

    numbers, the operation will generate a sum lf the operands arestrings, then the operation would produce a third string byconcatenation

  • 7/29/2019 1568778_634861630098116250

    20/23

    POLYMORPHISM [CONT..]

    There are two types of polymorphism.

    Compile time polymorphism - It is achieved

    by overloading functions and operatorsIt is also called Static binding or Early

    binding.

    Run time polymorphism - It is achievedby overriding virtual functions.

    It is also called Dynamic binding.

  • 7/29/2019 1568778_634861630098116250

    21/23

    POLYMORPHISM [CONT..]

    Consider Function calculateInterestto understand

    the implementation of polymorphism.

    Polymorphism is achieved by overriding functioncalculateInterestin subclasses SavingAccount

    and FixedDepositAccount.

  • 7/29/2019 1568778_634861630098116250

    22/23

    POLYMORPHISM [CONT..]

    BankAccount

    Account_number

    Balance

    Owner

    Branch

    ShowBalance

    Calculate Interest

    Saving Account

    Account_number

    BalanceOwner

    Branch

    ShowBalance

    Calculate Interest

    Fixed Deposit

    Account

    Account_numberBalance

    Owner

    Branch

    ShowBalance

    Calculate Interest

    For saving account

    Interest =

    P*(N/12)*(R/100)

    For Fixed

    Deposit account

    Interest =P*N*(R/100)

  • 7/29/2019 1568778_634861630098116250

    23/23

    SUMMARY:

    Encapsulation is accomplished by using Class.

    Keeps data and methods that accesses that data

    into a single unit

    Abstraction represents the essential features

    without including the background details.

    Inheritance helps a class to acquire attributes and

    behavior of another class.

    Polymorphism allows object to behave in

    different forms.