SlideShare a Scribd company logo
1 of 38
OOP
OBJECT-ORIENTED PROGRAMMING
• OOP is mainly a program design philosophy.
• OOP uses a different set of programming languages than old
procedural programming languages (C, Pascal, etc..,)
• Everything in OOP is grouped as self sustainable “objects”.
• Hence, you gain re-usability by means of four main object-
oriented programming concepts.
• In OOP programmers define not only the data type of data
structure, but also the type of operations/methods(functions)
that can be applied to the data structure.
• In this way, the data structure becomes an object that includes
both data and functions (methods) in one unit. In addition,
programmers can create relationships between one object and
another.
• For example, Objects can inherit characteristics from other
objects.
Key idea in object-oriented:
The real world can be “accurately” described as a collection of
objects that interact.
Basic Terminology:
Object
usually a person, place or thing ( a noun)
Method
an action performed by an object (a verb)
Property or attribute
Characteristics of certain object.
Class
a category of similar objects, does not hold any values of the
object’s attributes/properties
Classes and Objects
• A class is a prototype, idea, and blueprint for creating objects.
• An object is an instance of a class
• For example, in C++ we define classes, which in turn are
used to create objects
• A class has a constructor for creating objects
• Class is composed of three things: its name,
attributes/properties, and methods.
Class
Objects:
Instances of the class
Class Properties:
Belong to the class
Instance Properties:
Belong to the object
Methods:
Functions of class
Class:
A class is a definition of
objects with the same
properties and the same
methods
class Bicycle {
int speed = 0;
int gear = 1;
void changeGear (int newValue) {
gear = newValue;
}
void speedUp (int increment) {
speed = speed + increment;
}
void applyBreakes (int decrement) {
speed = speed – decrement;
}
Account
Owner
Balance
Account Number
Transaction Log
Deposit Account
Interest Rate
Current Account
Over Draft Limit
Example:
Almost everything in the world can be represented as an Object
• A flower, a tree, an animal
• A student, a professor
• A desk, a chair, a classroom, a building
• A university, a city, a country
• The world, the universe
• A subject such as CS, IS, Math, History
• An information system, financial, legal, etc…,
What is an Object?
An object is an instance of a class.
Informally, an object represents an entity, either physical, conceptual, or
software.
Physical entity
truck
Conceptual entity
chemical process
Software entity
linked list
Formal definition of an “Object”
An Object is a computational entity that:
• Encapsulates some state
• Is able to perform actions, or methods, on this state
• Communicates with other objects via message passing
Classes & Objects
“X” CAR
Property
Plate No :
AD47483
Color : Blue
Manufacturer :
Mercedes
Model : Classic
Gear Type :
Automatic
Method
Moves forward
Moves backward
Moves right
Moves left
Stops
Time
Hour
Minute
void addMinutes( int m )
inTime
Attributes:
Hour = 8
Minute = 30
Methods:
void addMinutes( int m
)
Class
inTime
Attributes:
Hour = 8
Minute = 30
Methods:
void addMinutes( int m
)
Objects
• Each copy of an object from a particular class is called an instance of the class
• The act of creating a new instance of an class is called instantiation .
Class Object
Class is a data type Object is an instance of class
It generates OBJECTS It gives life to CLASS
Does not occupy memory location It occupies memory locatio
It cannot manipulated because it is not
available in memory
It can be manipulated
Encapsulation
• Is the inclusion of property and method within a class/object in
which it needs to function property.
• Also, enables reusability of an instant of an already
implemented class within a new class while hiding and
protecting the method and properties from the client classes
• The class is kind of a container or capsule or a cell, which
encapsulate the set if methods, attributes and properties to
provide its indented functionalities to other classes
• In that sense, encapsulation also allows a class to change its
internal implementation without hurting the overall functioning
of the system
• That idea of encapsulation is to hide how a class does its
operations while allowing requesting its operations
Example:
Let’s say we have a class called “Date”(day, month, year). And then
you need to define another class called “Person” that has the
following attributes (first name, last name, and birthdate). So in
this case we can instantiate an object from class “Date” inside
class “Person”
Encapsulation – Benefits
Ensures that structural changes remain local :
• Changing the class internals does not affect any code outside
of the class
• Changing method’s implementation does not reflect the clients
using them
Encapsulation allows adding some logic when accessing clients
data
• Example: validation on modifying a property value
Hiding implementation details reduces complexity
• Easier maintenance
Inheritance
• Inheritance – a way of organizing classes
• Term comes from inheritance of traits likes eye color, hair color,
and so on
• Classes with properties in common can be grouped so that their
common properties are only defined once in parent class
• Superclass – inherit its attributes and methods to the
subclass(es)
• Subclass – can inherit all its superclass attributes and methods
besides having its own unique attributes and methods
 Inheritance allows child classes to inherit the characteristics of
existing parent class
• Attributes (fields and properties)
• Operations (methods)
 Child class can extend the parent class
• Add new fields and methods
• Redefine methods (modify existing behavior)
 A class can implement an interface by providing
implementation for all its methods
Benefits:
• Expresses commonality among classes/objects
• Allows code reusability
• Highlights relationships
• Helps in code organization
Feature 1
Feature 2
Feature 1
Feature 2
------------------------
Feature 3
Base Class
Derived Class (inherited from base class)
Features of base class
Features of base class accessible to derived class
because of inheritance
Features defined in derived class
Example:
Person
------------------------------
Name : String
Address : String
Student
-----------------------
School : String
-----------------------------
Name : String
Address : String
Employee
---------------------------------
Company : String
Salary : double
---------------------------------
Name : String
Address : String
Base class
Derived class
Derived class
Vehicle
School Bus
Sports Car
Sedan Luxury Bus
Bus
Motor Cycle
Automobile
Super Class
Subclasses
Example: Single Inheritance
One class inherits from another
Account
---------------------
Balance
Name
Number
---------------------
Withdraw
Statement
Savings Currents
Superclass
(parent)
Subclass
(child)
Example: Multiple Inheritance
A class can inherit from several other classes
Flying Thing Animal
Horse
Wolf
Bird
Helicopter
Airplane
Multiple Inheritance
Abstraction:
• Abstraction is a design principle
• Is the process of removing characteristics from something in order
to reduce it to set of essential characteristics.
• Through the process of abstraction, a programmer hides all but
the relevant data about a class in order to reduce complexity and
increase reusability
• Abstraction is a basic representation of a concept
• Abstraction allows programmers to represent complex real world
in the simplest manner
• It is a process of identifying the relevant qualities and behaviors
of an object should possess, in other word represent the necessary
features without representing the background details
• You should always use abstraction to ease reusability, and
understanding for the design and enable extension
• An abstract class, which declared with the “abstract” keyword,
cannot be instantiated
• It can only be used as a super-class for other classes that extend
the abstract class.
• Abstract class is a design concept and implementation gets
completed when it is being realized by a subclass.
Abstraction – types of classes
Person
Abstract Class
Concrete Class
Teacher Student
Can be instantiated directly
DOB:
Name:
Address:
Specialization:
Academic Title:
Etc…,
DOB:
Name:
Address:
GPA:
Courses:
Etc…,
DOB:
Name:
Address:
Can be instantiated directly Can’t be instantiated directly
• An abstract class is a class that may not have any direct instances.
• An abstract operation is an operation that it is incomplete and
requires a child to supply an implementation of the operation
Shape
{abstract}
draw() {abstract}
Circle
draw()
Rectangle
draw()
 Abstract class
 Abstract operation
Polymorphism:
• Encapsulation, Inheritance, and Abstraction concepts are very
related to Polymorphism
• Polymorphisms is a generic term that means ‘many shapes’. More
precisely Polymorphisms means the ability to request that the
same methods be performed by a wide range of different types of
things
• In OOP, polymorphisms is a technical issue and principle
• It is achieved by using many different techniques named method
overloading, operator overloading, and method overriding
• An object has “multiple identities”, based on its class inheritance
tree
• It can be used in different ways
Polymorphism – Abstract class:
• It is a class that you cannot instantiate from, however, you use
it to dominate and specify how the minimum requirements in an
inherited classes should be
public abstract class Robot {
public virtual abstract void Move ( )
// abstract move needs
}
public class LeggedRobot:Robot {
public override void Move() {
//actions of legged robot to move
}
}
public class WheeledRobot:Robot {
public override void Move() {
// actions of Wheeled robot to move
}
}
public void moveRobot (Robot A) {
A.Move();
}
public moveAllRobots() {
LeggedRobot lr = new LeggedRobot();
WheeledRobot wr = new WheeledRobot();
moveRobot(lr);
moveRobot(wr);
}
Advantages of OOP
• Code reuse and recycling
• Improved software-development productivity
• Improved software maintainability
• Faster development
• Lower cost of development
• Higher-quality software
• Encapsulation
Disadvantages of OOP:
• Steep learning curve
• Could lead to larger program sizes
• Could produce slower programs

More Related Content

Similar to OOP Presentation.pptx

Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisLuis Goldster
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisYoung Alista
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisHoang Nguyen
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisFraboni Ec
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisTony Nguyen
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisJames Wong
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysisHarry Potter
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Abdullah Jan
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oopcolleges
 
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
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Getachew Ganfur
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptxYashKoli22
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_febRaj Shah
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Ganapathi M
 

Similar to OOP Presentation.pptx (20)

Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Ooad ch 2
Ooad ch 2Ooad ch 2
Ooad ch 2
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Introduction to oop
Introduction to oopIntroduction to oop
Introduction to oop
 
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
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Oops
OopsOops
Oops
 
CPP-Unit 1.pptx
CPP-Unit 1.pptxCPP-Unit 1.pptx
CPP-Unit 1.pptx
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
8 oo approach&uml-23_feb
8 oo approach&uml-23_feb8 oo approach&uml-23_feb
8 oo approach&uml-23_feb
 
OOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptxOOSD1-unit1_1_16_09.pptx
OOSD1-unit1_1_16_09.pptx
 
Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0Object oriented analysis_and_design_v2.0
Object oriented analysis_and_design_v2.0
 

Recently uploaded

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

OOP Presentation.pptx

  • 2. • OOP is mainly a program design philosophy. • OOP uses a different set of programming languages than old procedural programming languages (C, Pascal, etc..,) • Everything in OOP is grouped as self sustainable “objects”. • Hence, you gain re-usability by means of four main object- oriented programming concepts.
  • 3. • In OOP programmers define not only the data type of data structure, but also the type of operations/methods(functions) that can be applied to the data structure. • In this way, the data structure becomes an object that includes both data and functions (methods) in one unit. In addition, programmers can create relationships between one object and another. • For example, Objects can inherit characteristics from other objects.
  • 4. Key idea in object-oriented: The real world can be “accurately” described as a collection of objects that interact.
  • 5. Basic Terminology: Object usually a person, place or thing ( a noun) Method an action performed by an object (a verb) Property or attribute Characteristics of certain object. Class a category of similar objects, does not hold any values of the object’s attributes/properties
  • 6. Classes and Objects • A class is a prototype, idea, and blueprint for creating objects. • An object is an instance of a class • For example, in C++ we define classes, which in turn are used to create objects • A class has a constructor for creating objects • Class is composed of three things: its name, attributes/properties, and methods.
  • 7. Class Objects: Instances of the class Class Properties: Belong to the class Instance Properties: Belong to the object Methods: Functions of class
  • 8. Class: A class is a definition of objects with the same properties and the same methods class Bicycle { int speed = 0; int gear = 1; void changeGear (int newValue) { gear = newValue; } void speedUp (int increment) { speed = speed + increment; } void applyBreakes (int decrement) { speed = speed – decrement; }
  • 9. Account Owner Balance Account Number Transaction Log Deposit Account Interest Rate Current Account Over Draft Limit Example:
  • 10. Almost everything in the world can be represented as an Object • A flower, a tree, an animal • A student, a professor • A desk, a chair, a classroom, a building • A university, a city, a country • The world, the universe • A subject such as CS, IS, Math, History • An information system, financial, legal, etc…, What is an Object? An object is an instance of a class.
  • 11. Informally, an object represents an entity, either physical, conceptual, or software. Physical entity truck Conceptual entity chemical process Software entity linked list
  • 12. Formal definition of an “Object” An Object is a computational entity that: • Encapsulates some state • Is able to perform actions, or methods, on this state • Communicates with other objects via message passing
  • 13. Classes & Objects “X” CAR Property Plate No : AD47483 Color : Blue Manufacturer : Mercedes Model : Classic Gear Type : Automatic Method Moves forward Moves backward Moves right Moves left Stops
  • 14. Time Hour Minute void addMinutes( int m ) inTime Attributes: Hour = 8 Minute = 30 Methods: void addMinutes( int m ) Class inTime Attributes: Hour = 8 Minute = 30 Methods: void addMinutes( int m ) Objects
  • 15. • Each copy of an object from a particular class is called an instance of the class • The act of creating a new instance of an class is called instantiation . Class Object Class is a data type Object is an instance of class It generates OBJECTS It gives life to CLASS Does not occupy memory location It occupies memory locatio It cannot manipulated because it is not available in memory It can be manipulated
  • 17. • Is the inclusion of property and method within a class/object in which it needs to function property. • Also, enables reusability of an instant of an already implemented class within a new class while hiding and protecting the method and properties from the client classes • The class is kind of a container or capsule or a cell, which encapsulate the set if methods, attributes and properties to provide its indented functionalities to other classes • In that sense, encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system • That idea of encapsulation is to hide how a class does its operations while allowing requesting its operations
  • 18. Example: Let’s say we have a class called “Date”(day, month, year). And then you need to define another class called “Person” that has the following attributes (first name, last name, and birthdate). So in this case we can instantiate an object from class “Date” inside class “Person”
  • 19. Encapsulation – Benefits Ensures that structural changes remain local : • Changing the class internals does not affect any code outside of the class • Changing method’s implementation does not reflect the clients using them Encapsulation allows adding some logic when accessing clients data • Example: validation on modifying a property value Hiding implementation details reduces complexity • Easier maintenance
  • 21. • Inheritance – a way of organizing classes • Term comes from inheritance of traits likes eye color, hair color, and so on • Classes with properties in common can be grouped so that their common properties are only defined once in parent class • Superclass – inherit its attributes and methods to the subclass(es) • Subclass – can inherit all its superclass attributes and methods besides having its own unique attributes and methods
  • 22.  Inheritance allows child classes to inherit the characteristics of existing parent class • Attributes (fields and properties) • Operations (methods)  Child class can extend the parent class • Add new fields and methods • Redefine methods (modify existing behavior)  A class can implement an interface by providing implementation for all its methods
  • 23. Benefits: • Expresses commonality among classes/objects • Allows code reusability • Highlights relationships • Helps in code organization
  • 24. Feature 1 Feature 2 Feature 1 Feature 2 ------------------------ Feature 3 Base Class Derived Class (inherited from base class) Features of base class Features of base class accessible to derived class because of inheritance Features defined in derived class
  • 25. Example: Person ------------------------------ Name : String Address : String Student ----------------------- School : String ----------------------------- Name : String Address : String Employee --------------------------------- Company : String Salary : double --------------------------------- Name : String Address : String Base class Derived class Derived class
  • 26. Vehicle School Bus Sports Car Sedan Luxury Bus Bus Motor Cycle Automobile Super Class Subclasses
  • 27. Example: Single Inheritance One class inherits from another Account --------------------- Balance Name Number --------------------- Withdraw Statement Savings Currents Superclass (parent) Subclass (child)
  • 28. Example: Multiple Inheritance A class can inherit from several other classes Flying Thing Animal Horse Wolf Bird Helicopter Airplane Multiple Inheritance
  • 29. Abstraction: • Abstraction is a design principle • Is the process of removing characteristics from something in order to reduce it to set of essential characteristics. • Through the process of abstraction, a programmer hides all but the relevant data about a class in order to reduce complexity and increase reusability • Abstraction is a basic representation of a concept
  • 30. • Abstraction allows programmers to represent complex real world in the simplest manner • It is a process of identifying the relevant qualities and behaviors of an object should possess, in other word represent the necessary features without representing the background details • You should always use abstraction to ease reusability, and understanding for the design and enable extension
  • 31. • An abstract class, which declared with the “abstract” keyword, cannot be instantiated • It can only be used as a super-class for other classes that extend the abstract class. • Abstract class is a design concept and implementation gets completed when it is being realized by a subclass.
  • 32. Abstraction – types of classes Person Abstract Class Concrete Class Teacher Student Can be instantiated directly DOB: Name: Address: Specialization: Academic Title: Etc…, DOB: Name: Address: GPA: Courses: Etc…, DOB: Name: Address: Can be instantiated directly Can’t be instantiated directly
  • 33. • An abstract class is a class that may not have any direct instances. • An abstract operation is an operation that it is incomplete and requires a child to supply an implementation of the operation Shape {abstract} draw() {abstract} Circle draw() Rectangle draw()  Abstract class  Abstract operation
  • 34. Polymorphism: • Encapsulation, Inheritance, and Abstraction concepts are very related to Polymorphism • Polymorphisms is a generic term that means ‘many shapes’. More precisely Polymorphisms means the ability to request that the same methods be performed by a wide range of different types of things • In OOP, polymorphisms is a technical issue and principle • It is achieved by using many different techniques named method overloading, operator overloading, and method overriding
  • 35. • An object has “multiple identities”, based on its class inheritance tree • It can be used in different ways Polymorphism – Abstract class: • It is a class that you cannot instantiate from, however, you use it to dominate and specify how the minimum requirements in an inherited classes should be
  • 36. public abstract class Robot { public virtual abstract void Move ( ) // abstract move needs } public class LeggedRobot:Robot { public override void Move() { //actions of legged robot to move } } public class WheeledRobot:Robot { public override void Move() { // actions of Wheeled robot to move } } public void moveRobot (Robot A) { A.Move(); } public moveAllRobots() { LeggedRobot lr = new LeggedRobot(); WheeledRobot wr = new WheeledRobot(); moveRobot(lr); moveRobot(wr); }
  • 37. Advantages of OOP • Code reuse and recycling • Improved software-development productivity • Improved software maintainability • Faster development • Lower cost of development • Higher-quality software • Encapsulation
  • 38. Disadvantages of OOP: • Steep learning curve • Could lead to larger program sizes • Could produce slower programs