SlideShare a Scribd company logo
1 of 33
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

Similar to 4-OOPS.pptx

Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Getachew Ganfur
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application DevelopmentDhaval Kaneria
 
Concepts for Object Oriented Databases.ppt
Concepts for Object Oriented Databases.pptConcepts for Object Oriented Databases.ppt
Concepts for Object Oriented Databases.pptnafsigenet
 
Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritanceTej Kiran
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaGlenn Guden
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientationHoang Nguyen
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxMIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxelsagalgao
 
Kelis king - introduction to software design
Kelis king -  introduction to software designKelis king -  introduction to software design
Kelis king - introduction to software designKelisKing
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objectsmcollison
 
static members in object oriented program.pptx
static members in object oriented program.pptxstatic members in object oriented program.pptx
static members in object oriented program.pptxurvashipundir04
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesDigitalDsms
 
10-System-ModelingFL22-sketch-19122022-091234am.pptx
10-System-ModelingFL22-sketch-19122022-091234am.pptx10-System-ModelingFL22-sketch-19122022-091234am.pptx
10-System-ModelingFL22-sketch-19122022-091234am.pptxhuzaifaahmed79
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 

Similar to 4-OOPS.pptx (20)

Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Concepts for Object Oriented Databases.ppt
Concepts for Object Oriented Databases.pptConcepts for Object Oriented Databases.ppt
Concepts for Object Oriented Databases.ppt
 
Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritance
 
Object Oriented Programming Concepts using Java
Object Oriented Programming Concepts using JavaObject Oriented Programming Concepts using Java
Object Oriented Programming Concepts using Java
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
Unit ii
Unit iiUnit ii
Unit ii
 
MIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptxMIT302 Lesson 2_Advanced Database Systems.pptx
MIT302 Lesson 2_Advanced Database Systems.pptx
 
Kelis king - introduction to software design
Kelis king -  introduction to software designKelis king -  introduction to software design
Kelis king - introduction to software design
 
Ch03
Ch03Ch03
Ch03
 
Pi j2.3 objects
Pi j2.3 objectsPi j2.3 objects
Pi j2.3 objects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
Module 3 Class and Object.ppt
Module 3 Class and Object.pptModule 3 Class and Object.ppt
Module 3 Class and Object.ppt
 
static members in object oriented program.pptx
static members in object oriented program.pptxstatic members in object oriented program.pptx
static members in object oriented program.pptx
 
Introduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book NotesIntroduction to C++ Class & Objects. Book Notes
Introduction to C++ Class & Objects. Book Notes
 
10-System-ModelingFL22-sketch-19122022-091234am.pptx
10-System-ModelingFL22-sketch-19122022-091234am.pptx10-System-ModelingFL22-sketch-19122022-091234am.pptx
10-System-ModelingFL22-sketch-19122022-091234am.pptx
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 

Recently uploaded

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 

Recently uploaded (20)

College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

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