SlideShare a Scribd company logo
1 of 60
OBJECT-ORIENTED
PROGRAMMING
Mimi OpkinsCECS 277
Objects Are Black Boxes
Code
Data
Message
Message
Objects are Building Blocks
Objects and Instances
 An object is a self-contained element of a
computer program that represents a related
group of features and is designed to
accomplish specific tasks
 Objects are also called instances.
Object-Oriented Terminology
Object Inheritance
Instance Class
Behavior Methods
State Variables
Encapsulation Message
Polymorphism Superclass
State and Behavior
 All real-world objects have state and behavior
 A software object maintains its state in
variables and its behavior in methods.
Instance Variables and Methods
 Variables and methods associated with a
particular object
 An instance variable is an item of information
that defines an attribute or state
 An instance method is used to implement
behavior
Object Diagram
Private
Implementation
Details
Public Interfaces
Public Interfaces
Public Interfaces Public Interfaces
Car Object Diagram
60 mph
Overdrive
Wipers Off
Change Gears
Turn on/off wipers
Accelerate Brake
Encapsulation
Hiding information in an object’s center and then
providing a public interface for interacting with
it is called encapsulation
Benefits of Objects
 Modularity – source code for an object can be
independent from the source code for other
objects
 Information Hiding – private information is kept
hidden from the public interface
Messages
Software objects
interact and
communicate by
sending messages
to each other
Rover, Speak!
Bark!
Bark!
Messages With More Meaning
Back Up
changeGears(reverse)
Message Components
 The object to whom the message is addressed
 The name of the method to perform
 Any parameters needed
Benefits of Messages
 Methods – an object’s behavior is expressed
through its methods so passing messages
supports all possible interaction between
objects
 Location – objects don’t need to be in the
same process or even on the same machine to
send and receive messages
Classes
 The most important feature of Object-Oriented
Programming
 Classes embody all features of a set of objects
 Define classes of objects
 Software blueprint
Definition of Class
 A class is a blueprint or prototype that defines
the variables and methods common to all
objects of certain kind.
 It is a template used to create multiple objects
with similar features
Class Variables and Methods
 A class variable is an item of information that
defines an attribute of an entire class.
 Class methods implement behavior for the
entire class.
Static Variables and Methods
 Static variables apply to the class itself and to all
of its instances
 Can access static variables and methods from
an instance of the class or directly by the class
 You don’t have to instantiate a class to use its
class variables and class methods
 Static methods only operate on class variables
Benefits of Classes
 Reusability – programmers can use the same
class and therefore the same code over and
over again to create different objects
Inheritance
 Inheritance is the mechanism that enables one
class to inherit all of the state and behavior of
another class
 Through inheritance, a class has all the
functionality of an existing class
 A new class can be created by only indicating
how it is different from an existing class
Superclass and Subclass
 A parent-child relationship
 A class that inherits from another class is a
subclass
 The class that gives the inheritance is the
superclass
Car Class Hierarchy
Car
SUV Mini Van Sports Car
Override
 Subclasses can override inherited methods and
provide specialized implementations for those
methods
 Overriding means to create a different method
definition for a method inherited from a subclass
 Overriding a method can be accomplished by
passing a different number of different types of
parameters
Benefits of Inheritance
 Specialized behavior – subclasses provide
specialized behaviors from the basis of
common variables and methods provided by
the superclass
 Abstract Classes – an abstract class defines
generic behavior
 Reuse – Don’t start code from scratch. Reuse
existing classes
Polymorphism
 By inheriting its superclass’ features, an
subclass is still a member of the superclass. It
can execute all of it’s methods as well as those
of the superclass. This ability to be both a
member of subclass and a superclass is called
polymorphism.
 In other words, a sports car is still a car
Comparison to Procedural
Languages
 Object-Oriented Programming
 Defines the “what” or the classes first
 Then the “how”
Procedure-Oriented
Programming
 First you identify the task to be performed
then:
1. Top-Down Approach -- by a step-wise
refinement, break the tasks into subtasks
2. Bottom-Up Approach – write procedures to
solve simple tasks and combine them into more
sophisticated procedures
 Most Programmers use a mixture of these
two approaches
Advantages of Object-Oriented
Programming
 Classes provide a convenient clustering
mechanism for methods
 The Object-Oriented structure is much
easier to grasp by the programmer or to
handle by teams of programmers
 Encapsulation – classes hide their data
representation from all code except their
own classes
Finding a Data-Related Bug
Global
Data
function
function
function
function
function
Object Data
Object Data
Object Data
method
method
method
method
method
Procedural Approach Object-Oriented Approach
Other Differences
 Modules
 Single Entity
 Forced Organization
 Classes
 Multiple Entities
 Natural Organization
Object-Oriented Design
Furry Household Pet Class
(Abstract)
Cat Class
Dog Class
Rabbit Class
An Object-Oriented Program
 When we write an Object-Oriented Program,
we design and construct a set of classes
 When the program runs, objects are created
from those classes
 We need to create the right set of classes to
accomplish what the program needs to do
Dragon State
 Color – yellow, red, green
 Attitude – mean, angry, playful
 Appetite – full, hungry
Dragon Behavior
 Get angry
 Calm down
 Eat a knight
 Breath fire
Reasons for Calling Methods
 To report a change to another object
 To tell the other object to change something
about itself
 To ask another object to do something
Dragon Scenario
 Dragon Object
 IamDead
Instance Method
 NumberofDragons
Class Variable
 ReduceDragons
Class Method
 Knight Object
 Sir Galahad
Instance Variable
 ChopOffDragonHead
Instance Method
Organizing Classes
 Determine if classes make up a class
hierarchy with subclasses
 Functionality that is common to multiple
classes can be put in superclasses
 Changes to a superclass are automatically
reflected in all their subclases
Monster Class Hierarchy
Monster
Flying Monster Swimming Monster
Flying Monster Class Hierarchy
Flying Monster
Mammal Reptile Amphibian
Four-Legged Flying Monster Two-Legged Flying Monster
Steps for Object-Oriented Programming
Design
1. Break down objects to their smallest
features
2. Look for commonality between the objects
3. Look for differences between the objects
4. Find the largest commonality between all
objects
5. Put the remaining common objects together
and repeat
Break Down Code to its Smallest
Features
Object Feature
Creatures Location, size, power level, capability to
attack, maneuverability
Power Pieces Must be drawn, location, power level
Bullets Capability to be fired
Main Character Capability to receive commands from the
user, capability to move around the maze
according to these commands, capability to
attack, location, size
Look For Commonality Between the
Objects
 Look for all the common relationships
between each of the objects
 The main difference between the creatures and
the main character is who controls them
 Have main character and creature share code
with the exception of the code to move them
Look For Difference Between the
Objects
 Find the differences between each of the
objects
 Look for relationships that unite and separate
all of the objects
 The bullets move and the power pieces don’t
 The computer controls creatures and the user
controls the main character
Find the Largest Commonality Between
All Objects
Draw Object
All Game Pieces
Put Remaining Common Objects
Together and Repeat
Draw Object
Creature Power Pieces/Bullets
Main Character
The “Big Example”
We’re going to take all the Object-Oriented
Programming and Object-Oriented Design
concepts and ideas and write a Science
Fiction Movie entitled…
“Programmers In Space”
Space Ship
Space Ship
Has a certain number of space shuttles
Has a certain number of imaging chambers
Has a certain number of officers
Has a certain number of aliens
Is located somewhere
Exists at a certain time
A typical Space Ship would have
Number of shuttles = 2
Location = sigma quadrant
Time period = 2253
Main Plot
Space Ship CECS is a new Space Ship
Number of imaging chambers = 1
Number of officers = 3
Captain = Danny
Senior Officer = Bob
Senior Officer = Jody
Number of aliens = 5
Humanoids
Humanoids
Have a certain number of legs
Have a certain number of arms
Have a certain number of eyes
Have a certain number of noses
Have a certain number of ears
Have a certain number mouths
Have a name
Have a certain sex
Have a favorite weapon
Have a beverage preference
Humanoids (continued)
A Standard Humanoid would start with
Number of legs = 2
Number of arms = 2
Number of eyes = 2
Number of noses =1
Number of ears =2
Number mouths = 1
When someone asks for your name
Tell them your name
Aliens
Aliens extend the idea of Humanoids
An Alien
Has non-standard ears
A certain “look”
A prophetic saying
Some level of meanness
A certain quantity of dimodium phosphate tubes
For a given Alien
It will look evil
It will start out the day calm
It will not yet have captured any dimodium phosphate tubes
Alien Instance Variables and
Methods
Drink Beverage
Level of meanness goes up by one
How Mean Am I
Tell them how mean I am
Alien Class Variables and
Methods
Prophetic Saying
Same saying for all aliens of a given species
Repeat Prophetic Saying
Retrieve it from the sacred book
Passing Parameters
Capture Dimodium Phosphate Tubes (# of tubes)
Increase the quantity of dimodium phosphate tubes by
the (# of tubes) amount
Gloat that you have captured (# of tubes) of dimodium
phosphate
Repeat Prophetic Saying
Retrieve it from the sacred book
Main Routine
There is a Space Ship called CECS
Number of imaging chambers = 1
Number of officers = 3
Captain = Danny
Senior Officer = Bob
Senior Officer = Jody
Number of aliens = 5
There is a new Human called Jennifer
Jennifer is female
Jennifer favor weapon is a keyboard
Jennifer prefers to drink coffee
Main Routine (continued)
There is a new Alien name Bernie
Bernie is male
Bernie has pointy ears
Bernie’s favorite weapon is a test tube
Bernie prefers to drink Pepsi
The prophetic saying spoken by Bernie’s race is “What’s
the status of that ticket?”
Bernie drinks some Pepsi
Bernie tells Jennifer how mean he is
Bernie captures 23 tubes of dimodium phosphate
Bernie quotes his prophetic saying
Resources for this Presentation
 Campione, Mary and Walrath, Kathy. The Java Tutorial Second
Edition: Object-Oriented Programming for the Internet. Addison-
Wesley. Reading, Massachusetts. 1998.
 Claerbout, Johannes. Don’t Fear the Oop!.
http://sepwww.standford.edu/sep/josman/oop/oop1.htm. 1998.
 Horstmann, Cay and Cornell, Gary. Core Java 2: Volume 1 –
Fundamentals. Sun Microsoft Press. Palo Alto, California. 1999.
 Lemay, Laura and Cadenhead, Rogers. Teach Yourself Java 2 in 21
Days. Sams Publishing. Indianapolis, Indiana. 1999.
 Weber, Joseph L. Special Edition: Using Java 2 Platform. Que
Publishers. 1999.

More Related Content

Similar to Object-Oriented Programming.pptx

JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptxRaazIndia
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxKunalYadav65140
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented DesignAravinth NSP
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
Java for android developers
Java for android developersJava for android developers
Java for android developersAly Abdelkareem
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP conceptsAhmed Farag
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingmustafa sarac
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsMaryo Manjaruni
 
Ooad notes
Ooad notesOoad notes
Ooad notesNancyJP
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialscesarmendez78
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)dannygriff1
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2Rakesh Madugula
 

Similar to Object-Oriented Programming.pptx (20)

JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
2.oop concept
2.oop concept2.oop concept
2.oop concept
 
OOP design patterns
OOP design patternsOOP design patterns
OOP design patterns
 
Cs2305 programming paradigms lecturer notes
Cs2305   programming paradigms lecturer notesCs2305   programming paradigms lecturer notes
Cs2305 programming paradigms lecturer notes
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Java for android developers
Java for android developersJava for android developers
Java for android developers
 
Introduction to OOP concepts
Introduction to OOP conceptsIntroduction to OOP concepts
Introduction to OOP concepts
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
Jedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented conceptsJedi slides 2.1 object-oriented concepts
Jedi slides 2.1 object-oriented concepts
 
Ooad notes
Ooad notesOoad notes
Ooad notes
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
Is2215 lecture2 student(2)
Is2215 lecture2 student(2)Is2215 lecture2 student(2)
Is2215 lecture2 student(2)
 
Md02 - Getting Started part-2
Md02 - Getting Started part-2Md02 - Getting Started part-2
Md02 - Getting Started part-2
 
Lecture 5.pptx
Lecture 5.pptxLecture 5.pptx
Lecture 5.pptx
 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Object-Oriented Programming.pptx

  • 2.
  • 3. Objects Are Black Boxes Code Data Message Message
  • 5.
  • 6. Objects and Instances  An object is a self-contained element of a computer program that represents a related group of features and is designed to accomplish specific tasks  Objects are also called instances.
  • 7. Object-Oriented Terminology Object Inheritance Instance Class Behavior Methods State Variables Encapsulation Message Polymorphism Superclass
  • 8. State and Behavior  All real-world objects have state and behavior  A software object maintains its state in variables and its behavior in methods.
  • 9. Instance Variables and Methods  Variables and methods associated with a particular object  An instance variable is an item of information that defines an attribute or state  An instance method is used to implement behavior
  • 10. Object Diagram Private Implementation Details Public Interfaces Public Interfaces Public Interfaces Public Interfaces
  • 11. Car Object Diagram 60 mph Overdrive Wipers Off Change Gears Turn on/off wipers Accelerate Brake
  • 12. Encapsulation Hiding information in an object’s center and then providing a public interface for interacting with it is called encapsulation
  • 13. Benefits of Objects  Modularity – source code for an object can be independent from the source code for other objects  Information Hiding – private information is kept hidden from the public interface
  • 14. Messages Software objects interact and communicate by sending messages to each other Rover, Speak! Bark! Bark!
  • 15. Messages With More Meaning Back Up changeGears(reverse)
  • 16. Message Components  The object to whom the message is addressed  The name of the method to perform  Any parameters needed
  • 17. Benefits of Messages  Methods – an object’s behavior is expressed through its methods so passing messages supports all possible interaction between objects  Location – objects don’t need to be in the same process or even on the same machine to send and receive messages
  • 18. Classes  The most important feature of Object-Oriented Programming  Classes embody all features of a set of objects  Define classes of objects  Software blueprint
  • 19. Definition of Class  A class is a blueprint or prototype that defines the variables and methods common to all objects of certain kind.  It is a template used to create multiple objects with similar features
  • 20. Class Variables and Methods  A class variable is an item of information that defines an attribute of an entire class.  Class methods implement behavior for the entire class.
  • 21. Static Variables and Methods  Static variables apply to the class itself and to all of its instances  Can access static variables and methods from an instance of the class or directly by the class  You don’t have to instantiate a class to use its class variables and class methods  Static methods only operate on class variables
  • 22. Benefits of Classes  Reusability – programmers can use the same class and therefore the same code over and over again to create different objects
  • 23. Inheritance  Inheritance is the mechanism that enables one class to inherit all of the state and behavior of another class  Through inheritance, a class has all the functionality of an existing class  A new class can be created by only indicating how it is different from an existing class
  • 24. Superclass and Subclass  A parent-child relationship  A class that inherits from another class is a subclass  The class that gives the inheritance is the superclass
  • 25. Car Class Hierarchy Car SUV Mini Van Sports Car
  • 26. Override  Subclasses can override inherited methods and provide specialized implementations for those methods  Overriding means to create a different method definition for a method inherited from a subclass  Overriding a method can be accomplished by passing a different number of different types of parameters
  • 27. Benefits of Inheritance  Specialized behavior – subclasses provide specialized behaviors from the basis of common variables and methods provided by the superclass  Abstract Classes – an abstract class defines generic behavior  Reuse – Don’t start code from scratch. Reuse existing classes
  • 28. Polymorphism  By inheriting its superclass’ features, an subclass is still a member of the superclass. It can execute all of it’s methods as well as those of the superclass. This ability to be both a member of subclass and a superclass is called polymorphism.  In other words, a sports car is still a car
  • 29. Comparison to Procedural Languages  Object-Oriented Programming  Defines the “what” or the classes first  Then the “how”
  • 30. Procedure-Oriented Programming  First you identify the task to be performed then: 1. Top-Down Approach -- by a step-wise refinement, break the tasks into subtasks 2. Bottom-Up Approach – write procedures to solve simple tasks and combine them into more sophisticated procedures  Most Programmers use a mixture of these two approaches
  • 31. Advantages of Object-Oriented Programming  Classes provide a convenient clustering mechanism for methods  The Object-Oriented structure is much easier to grasp by the programmer or to handle by teams of programmers  Encapsulation – classes hide their data representation from all code except their own classes
  • 32. Finding a Data-Related Bug Global Data function function function function function Object Data Object Data Object Data method method method method method Procedural Approach Object-Oriented Approach
  • 33. Other Differences  Modules  Single Entity  Forced Organization  Classes  Multiple Entities  Natural Organization
  • 34. Object-Oriented Design Furry Household Pet Class (Abstract) Cat Class Dog Class Rabbit Class
  • 35. An Object-Oriented Program  When we write an Object-Oriented Program, we design and construct a set of classes  When the program runs, objects are created from those classes  We need to create the right set of classes to accomplish what the program needs to do
  • 36. Dragon State  Color – yellow, red, green  Attitude – mean, angry, playful  Appetite – full, hungry
  • 37. Dragon Behavior  Get angry  Calm down  Eat a knight  Breath fire
  • 38. Reasons for Calling Methods  To report a change to another object  To tell the other object to change something about itself  To ask another object to do something
  • 39. Dragon Scenario  Dragon Object  IamDead Instance Method  NumberofDragons Class Variable  ReduceDragons Class Method  Knight Object  Sir Galahad Instance Variable  ChopOffDragonHead Instance Method
  • 40. Organizing Classes  Determine if classes make up a class hierarchy with subclasses  Functionality that is common to multiple classes can be put in superclasses  Changes to a superclass are automatically reflected in all their subclases
  • 41. Monster Class Hierarchy Monster Flying Monster Swimming Monster
  • 42. Flying Monster Class Hierarchy Flying Monster Mammal Reptile Amphibian Four-Legged Flying Monster Two-Legged Flying Monster
  • 43. Steps for Object-Oriented Programming Design 1. Break down objects to their smallest features 2. Look for commonality between the objects 3. Look for differences between the objects 4. Find the largest commonality between all objects 5. Put the remaining common objects together and repeat
  • 44. Break Down Code to its Smallest Features Object Feature Creatures Location, size, power level, capability to attack, maneuverability Power Pieces Must be drawn, location, power level Bullets Capability to be fired Main Character Capability to receive commands from the user, capability to move around the maze according to these commands, capability to attack, location, size
  • 45. Look For Commonality Between the Objects  Look for all the common relationships between each of the objects  The main difference between the creatures and the main character is who controls them  Have main character and creature share code with the exception of the code to move them
  • 46. Look For Difference Between the Objects  Find the differences between each of the objects  Look for relationships that unite and separate all of the objects  The bullets move and the power pieces don’t  The computer controls creatures and the user controls the main character
  • 47. Find the Largest Commonality Between All Objects Draw Object All Game Pieces
  • 48. Put Remaining Common Objects Together and Repeat Draw Object Creature Power Pieces/Bullets Main Character
  • 49. The “Big Example” We’re going to take all the Object-Oriented Programming and Object-Oriented Design concepts and ideas and write a Science Fiction Movie entitled… “Programmers In Space”
  • 50. Space Ship Space Ship Has a certain number of space shuttles Has a certain number of imaging chambers Has a certain number of officers Has a certain number of aliens Is located somewhere Exists at a certain time A typical Space Ship would have Number of shuttles = 2 Location = sigma quadrant Time period = 2253
  • 51. Main Plot Space Ship CECS is a new Space Ship Number of imaging chambers = 1 Number of officers = 3 Captain = Danny Senior Officer = Bob Senior Officer = Jody Number of aliens = 5
  • 52. Humanoids Humanoids Have a certain number of legs Have a certain number of arms Have a certain number of eyes Have a certain number of noses Have a certain number of ears Have a certain number mouths Have a name Have a certain sex Have a favorite weapon Have a beverage preference
  • 53. Humanoids (continued) A Standard Humanoid would start with Number of legs = 2 Number of arms = 2 Number of eyes = 2 Number of noses =1 Number of ears =2 Number mouths = 1 When someone asks for your name Tell them your name
  • 54. Aliens Aliens extend the idea of Humanoids An Alien Has non-standard ears A certain “look” A prophetic saying Some level of meanness A certain quantity of dimodium phosphate tubes For a given Alien It will look evil It will start out the day calm It will not yet have captured any dimodium phosphate tubes
  • 55. Alien Instance Variables and Methods Drink Beverage Level of meanness goes up by one How Mean Am I Tell them how mean I am
  • 56. Alien Class Variables and Methods Prophetic Saying Same saying for all aliens of a given species Repeat Prophetic Saying Retrieve it from the sacred book
  • 57. Passing Parameters Capture Dimodium Phosphate Tubes (# of tubes) Increase the quantity of dimodium phosphate tubes by the (# of tubes) amount Gloat that you have captured (# of tubes) of dimodium phosphate Repeat Prophetic Saying Retrieve it from the sacred book
  • 58. Main Routine There is a Space Ship called CECS Number of imaging chambers = 1 Number of officers = 3 Captain = Danny Senior Officer = Bob Senior Officer = Jody Number of aliens = 5 There is a new Human called Jennifer Jennifer is female Jennifer favor weapon is a keyboard Jennifer prefers to drink coffee
  • 59. Main Routine (continued) There is a new Alien name Bernie Bernie is male Bernie has pointy ears Bernie’s favorite weapon is a test tube Bernie prefers to drink Pepsi The prophetic saying spoken by Bernie’s race is “What’s the status of that ticket?” Bernie drinks some Pepsi Bernie tells Jennifer how mean he is Bernie captures 23 tubes of dimodium phosphate Bernie quotes his prophetic saying
  • 60. Resources for this Presentation  Campione, Mary and Walrath, Kathy. The Java Tutorial Second Edition: Object-Oriented Programming for the Internet. Addison- Wesley. Reading, Massachusetts. 1998.  Claerbout, Johannes. Don’t Fear the Oop!. http://sepwww.standford.edu/sep/josman/oop/oop1.htm. 1998.  Horstmann, Cay and Cornell, Gary. Core Java 2: Volume 1 – Fundamentals. Sun Microsoft Press. Palo Alto, California. 1999.  Lemay, Laura and Cadenhead, Rogers. Teach Yourself Java 2 in 21 Days. Sams Publishing. Indianapolis, Indiana. 1999.  Weber, Joseph L. Special Edition: Using Java 2 Platform. Que Publishers. 1999.