SlideShare a Scribd company logo
DISCOVER . LEARN . EMPOWER
UNIVERSITY INSTITUTE OF
COMPUTING
Master of Computer Applications
Winning Camp – Content
MCA (TPP) - 2021 Batch
Logic Building
*
*
*
3
Why use OOP?
• Object Oriented Programming (OOP) is one of the most widely used programming paradigm
• Why is it extensively used?
• Well suited for building trivial and complex applications
• Allows re-use of code thereby increasing productivity
• New features can be easily built into the existing code
• Reduced production cost and maintenance cost
• Common programming languages used for OOP include C++, Java, and C#
• Object: models a
• Real world object (ex. computer, book, box)
• Concept (ex. meeting, interview)
• Process (ex. sorting a stack of papers or comparing two computers to measure their performance)
May create many objects from a given class
- Each object will have its own attribute, but will have identical behaviour.
• Class:
• prototype or blueprint from which objects are created
• The class construct provides a template (or blueprint) for the creation of objects.
• Classes specify what attributes and behaviour an object may have.
*
*
*
3
1. Objects & Classes
• Class has
• Set of attributes or properties that describes every object
• Set of behavior or actions that every object can perform
• Object has
• Set of data (value for each of its attribute)
• Set of actions that it can perform
• An identity
*
*
*
3
Objects & Classes
• In old style programming, you had:
• data, which was completely passive
• functions, which could manipulate any data
• An object contains both data and methods that manipulate that data
• An object is active, not passive; it does things
• An object is responsible for its own data
• But: it can expose that data to other objects
*
*
*
3
An object has behaviors
*
*
*
3
An object has state
• 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 this object and other objects
• Example: A CheckingAccount might have
• A balance (the internal state of the account)
• An owner (some object representing a person)
*
*
*
3
Real world example of Classes & objects
*
*
*
3
Real world example of Classes & objects
• A Class is a set of variables (to represent its attributes) and functions (to describe its behavior)
that act on its variables
• Object is an instance of a class that holds data (values) in its variables. Data can be accessed by its
functions
• Every object belongs to (is an instance of) a class
• An object may have fields, or variables
• The class describes those fields
• An object may have methods
• The class describes those methods
• A class is like a template, or cookie cutter
• You use the class’s constructor to make objects
*
*
*
3
Classes describe objects
• Every class object
- Has its own data members
- Has its own member functions (which are the same as other objects of the
same class have)
- When a member function accesses a data member
By default the function accesses the data member of the object to which it belongs!
- No special notation needed
*
*
*
3
Remember
• The Class construct
- Actually allows programmers to define new data types for representing information
- Class type objects can have both attribute and behaviour components
- Provides the object-oriented programming in C++
*
*
*
3
Class Data Types
*
*
*
3
Example of class
#include <iostream>
using namespace std;
class Circle
{
private:
// The radius of this circle
double radius;
public:
// Construct a default circle object
Circle()
{
radius = 1;
} // Construct a circle object
Circle(double newRadius)
{
radius = newRadius;
}
// Return the area of this circle
double getArea()
{
return radius * radius * 3.14159;
}
}; // Must place a semicolon here
int main()
{
Circle circle1(1.0);
Circle circle2(25);
Circle circle3(125);
cout << "The area of the circle of radius "
" 1.0 is " << circle1.getArea() << endl;
cout << "The area of the circle of radius "
“25 is " << circle2.getArea() << endl;
cout << "The area of the circle of radius "
“125 is " << circle3.getArea() << endl;
return 0;
}
*
*
*
3
Example of class
class Employee {
// Fields
private String name; //Can get but not change
private double salary; // Cannot get or set
// Constructor
Employee(String n, double s) {
name = n; salary = s;
}
// Methods
void pay () {
System.out.println("Pay to the order of " + name + " $" + salary);
}
public String getName() { return name; } // getter
}
*
*
*
3
Example of class
• instance = object
• field = instance variable
• method = function
• sending a message to an object = calling a function
• These are all approximately true
*
*
*
3
Approximate Terminology
*
*
*
3
C++ & Java
• In C++ there may be more than one root
• but not in Java!
• In C++ an object may have more than one parent (immediate superclass)
• but not in Java!
• Java has a single, strict hierarchy
• Extracting essential properties and behavior of an entity
• Class represents such an abstraction and is commonly referred to as an abstract data type
• Extract only the relevant properties of a real-world of or developing a class while ignoring the
inessentials
• For any problem, extract the relevant real-world object properties for software objects, while
ignoring inessentials
• Defines a view of the software object
*
*
*
3
2. Abstraction
*
*
*
3
Abstraction
*
*
*
3
Abstraction
Example - car
• Car dealer views a car from selling features standpoint
• Price, length of warranty, color, …
• Mechanic views a car from systems maintenance standpoint
• Size of the oil filter, type of spark plugs, …
*
*
*
3
3. Encapsulation and
Information Hiding
• Mechanism by which we combine data and the functions that manipulate the data into one unit
• Objects & Classes enforce encapsulation
• Group the attributes and behavior of an object together in a single data structure known as a class
• Data and functions are said to be encapsulated into a single entity – the class
• Data is concealed within a class, so that it cannot be accessed mistakenly by functions outside the class.
*
*
*
3
Encapsulation
• Steps
• Decompose an object into parts
• Hide and protect essential information
• Supply an interface that allows an object to be accessed in a controlled and useful manner
• Interface means that the internal representation of a class can be changed without affecting other system
parts
• Example - Radio
• Interface consists of controls and power and antenna connectors
• The details of how it works is hidden
• To install and use a radio
• Do not need to know anything about the radio’s electronics
*
*
*
3
Modularity
• Dividing an object into smaller pieces or “modules” so that the object is easier to understand and
• Most complex systems are modular
• Example - Car can be decomposed into subsystems
1. Cooling system
• Radiator Thermostat Water pump
2. Ignition system
• Battery Starter motor Spark plugs
*
*
*
3
Hierarchy
• Hierarchy
• Ranking or ordering of objects based on some relationship between them
• Helps us understand complex systems
• Example - a company hierarchy helps employees understand the company and their positions within it
• For complex systems, a useful way of ordering similar abstractions is a taxonomy
from least general to most general
• Classes are arranged in a tree like structure called a hierarchy
• The class at the root is named Object
• Every class, except Object, has a superclass
• A class may have several ancestors, up to Object
• When you define a class, you specify its superclass
• If you don’t specify a superclass, Object is assumed
• Every class may have one or more subclasses
*
*
*
3
Classes form a hierarchy
*
*
*
3
Hierarchy
*
*
*
3
4. Inheritance
• The process of creating new classes, called derived classes, from existing classes or base
classes creating a hierarchy of parent classes and child classes.
• The child classes inherit the attributes and behaviour of the parent classes.
• The derived class inherits the variables and functions of the base class and adds additional
ones!
• Provides the ability to re-use existing code
*
*
*
3
A variable can hold subclass objects
• Suppose B is a subclass of A
• A objects can be assigned to A variables
• B objects can be assigned to B variables
• B objects can be assigned to A variables, but
• A objects can not be assigned to B variables
• Every B is also an A but not every A is a B
• You can cast: bVariable = (B) aObject;
• In this case, Java does a runtime check
*
*
*
3
Objects inherit from superclasses
• A class describes fields and methods
• Objects of that class have those fields and methods
• But an object also inherits:
• the fields described in the class's superclasses
• the methods described in the class's superclasses
• A class is not a complete description of its objects!
*
*
*
3
Example of inheritance
class Person {
String name;
int age;
void birthday () {
age = age + 1;
}
}
class Employee
extends Person {
double salary;
void pay () { ...}
}
Every Employee has name and age fields and birthday method as well as a salary field and a pay method.
*
*
*
3
Inheritance Example
*
*
*
3
Inheritance Example
– Generally, the ability to appear in many forms
– More specifically, in OOP, it is the ability to redefine methods for derived classes
– Ability to process objects differently depending on their data type or class
– Giving different meanings to the same thing
*
*
*
3
5. Polymorphism
THANK YOU

More Related Content

PPTX
java part 1 computer science.pptx
PPT
Object -oriented analysis and design.ppt
PPTX
object oriented programing lecture 1
PPTX
OOP Presentation.pptx
PPTX
OOP Presentation.pptx
PPT
Object-oriented concepts
PDF
Programming Laboratory Unit 1.pdf
PDF
JAVA-PPT'S.pdf
java part 1 computer science.pptx
Object -oriented analysis and design.ppt
object oriented programing lecture 1
OOP Presentation.pptx
OOP Presentation.pptx
Object-oriented concepts
Programming Laboratory Unit 1.pdf
JAVA-PPT'S.pdf

Similar to 4-OOPS.pptx (20)

PPTX
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
PPTX
JAVA-PPT'S-complete-chrome.pptx
PPTX
JAVA-PPT'S.pptx
PDF
Core java complete notes - PAID call at +91-814-614-5674
PDF
Core java complete notes - Contact at +91-814-614-5674
PPTX
Object oriented programming
PPTX
UNIT - 1 Java Fundamentals, Basics of java
PPTX
1669609053088_oops_final.pptx
PDF
Oops concepts
PPTX
COMP111-Week-1_138439.pptx
PPTX
Intro to object oriented programming.pptx
PPTX
Java Programming - UNIT - 1, Basics OOPS, Differences
PPTX
General oop concept
PPTX
Opp concept in c++
PPT
Unit 1- Basic concept of object-oriented-programming.ppt
PPTX
OOSD1-unit1_1_16_09.pptx
PPTX
07 intro2 oop
PDF
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
PPTX
SKILLWISE - OOPS CONCEPT
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S.pptx
Core java complete notes - PAID call at +91-814-614-5674
Core java complete notes - Contact at +91-814-614-5674
Object oriented programming
UNIT - 1 Java Fundamentals, Basics of java
1669609053088_oops_final.pptx
Oops concepts
COMP111-Week-1_138439.pptx
Intro to object oriented programming.pptx
Java Programming - UNIT - 1, Basics OOPS, Differences
General oop concept
Opp concept in c++
Unit 1- Basic concept of object-oriented-programming.ppt
OOSD1-unit1_1_16_09.pptx
07 intro2 oop
UNIT1- OBJECT ORIENTED PROGRAMMING IN JAVA- AIML IT-SPPU
SKILLWISE - OOPS CONCEPT
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PPTX
web development for engineering and engineering
PPTX
Geodesy 1.pptx...............................................
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPT
Mechanical Engineering MATERIALS Selection
PDF
ETO & MEO Certificate of Competency Questions and Answers
DOCX
573137875-Attendance-Management-System-original
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
composite construction of structures.pdf
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
web development for engineering and engineering
Geodesy 1.pptx...............................................
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Internet of Things (IOT) - A guide to understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Lecture Notes Electrical Wiring System Components
Operating System & Kernel Study Guide-1 - converted.pdf
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
Arduino robotics embedded978-1-4302-3184-4.pdf
Mechanical Engineering MATERIALS Selection
ETO & MEO Certificate of Competency Questions and Answers
573137875-Attendance-Management-System-original
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
additive manufacturing of ss316l using mig welding
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
Ad

4-OOPS.pptx

  • 1. DISCOVER . LEARN . EMPOWER UNIVERSITY INSTITUTE OF COMPUTING Master of Computer Applications Winning Camp – Content MCA (TPP) - 2021 Batch Logic Building
  • 2. * * * 3 Why use OOP? • Object Oriented Programming (OOP) is one of the most widely used programming paradigm • Why is it extensively used? • Well suited for building trivial and complex applications • Allows re-use of code thereby increasing productivity • New features can be easily built into the existing code • Reduced production cost and maintenance cost • Common programming languages used for OOP include C++, Java, and C#
  • 3. • Object: models a • Real world object (ex. computer, book, box) • Concept (ex. meeting, interview) • Process (ex. sorting a stack of papers or comparing two computers to measure their performance) May create many objects from a given class - Each object will have its own attribute, but will have identical behaviour. • Class: • prototype or blueprint from which objects are created • The class construct provides a template (or blueprint) for the creation of objects. • Classes specify what attributes and behaviour an object may have. * * * 3 1. Objects & Classes
  • 4. • Class has • Set of attributes or properties that describes every object • Set of behavior or actions that every object can perform • Object has • Set of data (value for each of its attribute) • Set of actions that it can perform • An identity * * * 3 Objects & Classes
  • 5. • In old style programming, you had: • data, which was completely passive • functions, which could manipulate any data • An object contains both data and methods that manipulate that data • An object is active, not passive; it does things • An object is responsible for its own data • But: it can expose that data to other objects * * * 3 An object has behaviors
  • 6. * * * 3 An object has state • 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 this object and other objects • Example: A CheckingAccount might have • A balance (the internal state of the account) • An owner (some object representing a person)
  • 7. * * * 3 Real world example of Classes & objects
  • 8. * * * 3 Real world example of Classes & objects
  • 9. • A Class is a set of variables (to represent its attributes) and functions (to describe its behavior) that act on its variables • Object is an instance of a class that holds data (values) in its variables. Data can be accessed by its functions • Every object belongs to (is an instance of) a class • An object may have fields, or variables • The class describes those fields • An object may have methods • The class describes those methods • A class is like a template, or cookie cutter • You use the class’s constructor to make objects * * * 3 Classes describe objects
  • 10. • Every class object - Has its own data members - Has its own member functions (which are the same as other objects of the same class have) - When a member function accesses a data member By default the function accesses the data member of the object to which it belongs! - No special notation needed * * * 3 Remember
  • 11. • The Class construct - Actually allows programmers to define new data types for representing information - Class type objects can have both attribute and behaviour components - Provides the object-oriented programming in C++ * * * 3 Class Data Types
  • 13. #include <iostream> using namespace std; class Circle { private: // The radius of this circle double radius; public: // Construct a default circle object Circle() { radius = 1; } // Construct a circle object Circle(double newRadius) { radius = newRadius; } // Return the area of this circle double getArea() { return radius * radius * 3.14159; } }; // Must place a semicolon here int main() { Circle circle1(1.0); Circle circle2(25); Circle circle3(125); cout << "The area of the circle of radius " " 1.0 is " << circle1.getArea() << endl; cout << "The area of the circle of radius " “25 is " << circle2.getArea() << endl; cout << "The area of the circle of radius " “125 is " << circle3.getArea() << endl; return 0; } * * * 3 Example of class
  • 14. class Employee { // Fields private String name; //Can get but not change private double salary; // Cannot get or set // Constructor Employee(String n, double s) { name = n; salary = s; } // Methods void pay () { System.out.println("Pay to the order of " + name + " $" + salary); } public String getName() { return name; } // getter } * * * 3 Example of class
  • 15. • instance = object • field = instance variable • method = function • sending a message to an object = calling a function • These are all approximately true * * * 3 Approximate Terminology
  • 16. * * * 3 C++ & Java • In C++ there may be more than one root • but not in Java! • In C++ an object may have more than one parent (immediate superclass) • but not in Java! • Java has a single, strict hierarchy
  • 17. • Extracting essential properties and behavior of an entity • Class represents such an abstraction and is commonly referred to as an abstract data type • Extract only the relevant properties of a real-world of or developing a class while ignoring the inessentials • For any problem, extract the relevant real-world object properties for software objects, while ignoring inessentials • Defines a view of the software object * * * 3 2. Abstraction
  • 19. * * * 3 Abstraction Example - car • Car dealer views a car from selling features standpoint • Price, length of warranty, color, … • Mechanic views a car from systems maintenance standpoint • Size of the oil filter, type of spark plugs, …
  • 20. * * * 3 3. Encapsulation and Information Hiding • Mechanism by which we combine data and the functions that manipulate the data into one unit • Objects & Classes enforce encapsulation • Group the attributes and behavior of an object together in a single data structure known as a class • Data and functions are said to be encapsulated into a single entity – the class • Data is concealed within a class, so that it cannot be accessed mistakenly by functions outside the class.
  • 21. * * * 3 Encapsulation • Steps • Decompose an object into parts • Hide and protect essential information • Supply an interface that allows an object to be accessed in a controlled and useful manner • Interface means that the internal representation of a class can be changed without affecting other system parts • Example - Radio • Interface consists of controls and power and antenna connectors • The details of how it works is hidden • To install and use a radio • Do not need to know anything about the radio’s electronics
  • 22. * * * 3 Modularity • Dividing an object into smaller pieces or “modules” so that the object is easier to understand and • Most complex systems are modular • Example - Car can be decomposed into subsystems 1. Cooling system • Radiator Thermostat Water pump 2. Ignition system • Battery Starter motor Spark plugs
  • 23. * * * 3 Hierarchy • Hierarchy • Ranking or ordering of objects based on some relationship between them • Helps us understand complex systems • Example - a company hierarchy helps employees understand the company and their positions within it • For complex systems, a useful way of ordering similar abstractions is a taxonomy from least general to most general
  • 24. • Classes are arranged in a tree like structure called a hierarchy • The class at the root is named Object • Every class, except Object, has a superclass • A class may have several ancestors, up to Object • When you define a class, you specify its superclass • If you don’t specify a superclass, Object is assumed • Every class may have one or more subclasses * * * 3 Classes form a hierarchy
  • 26. * * * 3 4. Inheritance • The process of creating new classes, called derived classes, from existing classes or base classes creating a hierarchy of parent classes and child classes. • The child classes inherit the attributes and behaviour of the parent classes. • The derived class inherits the variables and functions of the base class and adds additional ones! • Provides the ability to re-use existing code
  • 27. * * * 3 A variable can hold subclass objects • Suppose B is a subclass of A • A objects can be assigned to A variables • B objects can be assigned to B variables • B objects can be assigned to A variables, but • A objects can not be assigned to B variables • Every B is also an A but not every A is a B • You can cast: bVariable = (B) aObject; • In this case, Java does a runtime check
  • 28. * * * 3 Objects inherit from superclasses • A class describes fields and methods • Objects of that class have those fields and methods • But an object also inherits: • the fields described in the class's superclasses • the methods described in the class's superclasses • A class is not a complete description of its objects!
  • 29. * * * 3 Example of inheritance class Person { String name; int age; void birthday () { age = age + 1; } } class Employee extends Person { double salary; void pay () { ...} } Every Employee has name and age fields and birthday method as well as a salary field and a pay method.
  • 32. – Generally, the ability to appear in many forms – More specifically, in OOP, it is the ability to redefine methods for derived classes – Ability to process objects differently depending on their data type or class – Giving different meanings to the same thing * * * 3 5. Polymorphism