logging in or signing up OOP_concept arif12743 Download Post to : URL : Related Presentations : Let's Connect Share Add to Flag Embed Email Send to Blogs and Networks Add to Channel Copy embed code: Embed: Flash iPad Dynamic Copy Does not support media & animations Automatically changes to Flash or non-Flash embed WordPress Embed Customize Embed URL: Copy Thumbnail: Copy The presentation is successfully added In Your Favorites. Views: 195 Category: Education License: All Rights Reserved Like it (0) Dislike it (0) Added: October 18, 2012 This Presentation is Public Favorites: 0 Presentation Description Object Oriented Programming Concepts Comments Posting comment... Premium member Presentation Transcript Object Oriented Concepts: Object Oriented Concepts By ARIFDefinition of OOP: Definition of 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.OOP’s Concepts: OOP’s Concepts Classes Objects Encapsulation Abstraction Inheritance Polymorphism We will consider an example to understand all the above OOP’s ConceptsEXAMPLE :: 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 transfer money between accounts with the help of functions provided by the system such as showbalance, updatebalance and calculateinterest.OOP’s Concept 1: Classes: OOP’s 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 variables for storing data and functions to performing operations on these data. The entire set of data and code of an object can be made a 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.OOP’s Concept 2: Objects: OOP’s Concept 2: Objects “Object is an instance of a 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)Classes and Objects [cont..]: Classes and 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 ObjectOOP’s Concept 3: Encapsulation: OOP’s 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 internal details 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 languages such as C# using accessor and mutator methodsEncapsulation [cont..] : Encapsulation [cont..] Class BankAccount Private: Account_number Private: Balance Private: Owner Private: Branch Public: ShowBalance Public: UpdateBalance Public: calculateInterestOOP’s Concept 4: Abstraction: OOP’s 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 does it. provides you a generalized view of your classes or object by providing relevant information . Classes use the concept of abstraction and are defined as a list of abstract attributes such as size, weight and cost, and functions to operate on these attributes. They encapsulate all the essential properties of the objects that are to be created. Since the classes use the concept of data abstraction, they are known as Abstract Data Types (ADT).Abstraction [cont..]: 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:Abstraction [cont..]: Abstraction [cont..] BankAccount Account_number Balance Owner Branch ShowBalance Abstract:calculateInterest Saving Account Account_number Balance Owner Branch ShowBalance Calculate Interest Fixed Deposit Account Account_number Balance Owner Branch ShowBalance Calculate Interest Abstract class calculateInterest having different implementationOOP’s Concept 5: Inheritance: OOP’s 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.Inheritance [cont..]: Inheritance [cont..] Single Inheritance Multi-Level Inheritance Class A Class B Class A Class B Class CInheritance [cont..]: Inheritance [cont..] 3. Hierarchical Inheritance 4. Multiple Inheritance Class A Class B Class C Class A Class B Class CInheritance [cont..]: Inheritance [cont..] 5. Multi-path/Hybrid Inheritance Class A Class B Class C Class DInheritance [cont..]: Inheritance [cont..] Current Account Fixed Deposit Account Savings Account Bank AccountInheritance [cont..]: Inheritance [cont..]OOP’s Concept 6: Polymorphism: OOP’s Concept 6: Polymorphism Polymorphism means “ one name many forms” . Essentially, Polymorphism is the capability of one object 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 different instances . The behavior depends upon the types of data used in the operation. For example, consider the operation of addition. For two numbers, the operation will generate a sum lf the operands are strings, then the operation would produce a third string by concatenationPolymorphism [cont..]: Polymorphism [cont..] There are two types of polymorphism. Compile time polymorphism - It is achieved by overloading functions and operators It is also called Static binding or Early binding. Run time polymorphism - It is achieved by overriding virtual functions. It is also called Dynamic binding.Polymorphism [cont..]: Polymorphism [cont..] Consider Function calculateInterest to understand the implementation of polymorphism. Polymorphism is achieved by overriding function calculateInterest in subclasses SavingAccount and FixedDepositAccount.Polymorphism [cont..]: Polymorphism [cont..] BankAccount Account_number Balance Owner Branch ShowBalance Calculate Interest Saving Account Account_number Balance Owner Branch ShowBalance Calculate Interest Fixed Deposit Account Account_number Balance Owner Branch ShowBalance Calculate Interest For saving account Interest = P*(N/12)*(R/100) For Fixed Deposit account Interest = P*N*(R/100)Summary:: 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.” You do not have the permission to view this presentation. In order to view it, please contact the author of the presentation.