Object-Oriented Concepts
Object-Oriented Concepts
Object-oriented concepts
To start with, a brief review of underlying themes
Abstraction: Process of identifying essential aspects of an entity and ignoring unimportant properties. - Concentrate on what an object is and what it does, before deciding how to implement it.
Encapsulation: Object contains both data structure and set of operations used to manipulate it. Information Hiding: Separate external aspects of an object from its internal details, which are hidden from outside. Allows internal details of object to be changed without affecting apps that use it, provided external details remain same. Provides data independence.
Attributes can be classified as simple or complex. Simple attribute can be a primitive type such as integer, string, etc., which takes on literal values. Complex attribute can contain collections and/or references. Reference attribute represents relationship. complex object: contains one or more complex atts
(b)
Classes
Class: Blueprint for defining a set of similar objects.
-Objects in a class are called instances. -Class is also an object with own class attributes and class methods.
Inheritance allows one class of objects to be defined as a special case of a more general class.
Special cases are subclasses and more general cases are superclasses. Generalization: process of forming a superclass 4 Types of Specialization: forming a subclass inheritance:
1. single Subclass inherits all properties of its superclass 2. multiple and can define its own unique properties. 3. repeated Subclass can redefine inherited methods. 4. selective All instances of subclass are instances of superclass. Principle of substitutability: instance of subclass can be used whenever method/construct expects instance of superclass. A KIND OF (AKO): Name for relationship between subclass and superclass
Types of inheritance
(a) (b)
Overriding Example: Might define method in Staff class to increment salary based on commission method void giveCommission(float branchProfit) { salary = salary + 0.02 * branchProfit; } May wish to perform different calculation for commission in Manager subclass: method void giveCommission(float branchProfit) { salary = salary + 0.05 * branchProfit; }
Polymorphism: Means many forms. Three types: 1. operation 2. Inclusion 3. parametric. Dynamic Binding: Runtime process of selecting appropriate method based on an objects type.
Example: With list consisting of an arbitrary no. of objects from the Staff hierarchy, we can write: list[i]. print and runtime system will determine which print() method to invoke depending on the objects (sub)type.