SlideShare a Scribd company logo
1 of 45
Programming Logic and Design
Eighth Edition
Chapter 10
Object-Oriented Programming
Objectives
In this chapter, you will learn about:
• The principles of object-oriented programming
• Classes
• Public and private access
• Ways to organize classes
• Instance methods
• Static methods
• Using objects
2Programming Logic and Design, Eighth Edition
Principles of Object-Oriented
Programming
3Programming Logic and Design, Eighth Edition
• Object-oriented programming (OOP)
– A style of programming that focuses on an application’s
data and the methods to manipulate that data
• Uses all of the familiar concepts from modular
procedural programming
– Variables, methods, passing arguments
– Sequence, selection, and looping structures
– But involves a different way of thinking
Principles of Object-Oriented
Programming (continued)
4Programming Logic and Design, Eighth Edition
• Important features of object-oriented languages
– Classes
– Objects
– Polymorphism
– Inheritance
– Encapsulation
5Programming Logic and Design, Eighth Edition
Classes and Objects
• Class
– Describes a group or collection of objects with common
attributes
• Object - One instance of a class
– Sometimes called one instantiation of a class
– When a program creates an object, it instantiates the
object
• Example
– Class name: dog
– Attributes: name, age, hasShots
– Methods: changeName, updateShots
Classes and Objects (continued)
6Programming Logic and Design, Eighth Edition
• Attributes
– Characteristics that define an object as part of a class
– Example
• Automobile’s attributes: make, model, year, and purchase price
• Methods
– Actions that alter, use, or retrieve the attributes
– Example
• Methods for changing an automobile’s running status, gear,
speed, and cleanliness
Classes and Objects (continued)
7Programming Logic and Design, Eighth Edition
• Think in an object-oriented manner
– Everything is an object
– Every object is a member of a class
• Is-a relationship
– “My oak desk with the scratch on top is a Desk”
• Class reusability
• Class’s instance variables
– Data components of a class that belong to every
instantiated object
– Often called fields
Classes and Objects (continued)
8Programming Logic and Design, Eighth Edition
• State
– A set of all the values or contents of a class object’s
instance variables
• Every object that is an instance of a class possesses
the same methods
• Create classes from which objects will be
instantiated
• Class client or class user
– A program or class that instantiates objects of another
prewritten class
Polymorphism
9Programming Logic and Design, Eighth Edition
• The world is full of objects
– A door is an object that needs to be open or closed
– But an “open” procedure works differently on different
objects
• Open a door
• Open a drawer
• Open a bank account
• Open a file
• Open your eyes
– One “open” procedure can open anything if it gets the
correct arguments
Inheritance
10Programming Logic and Design, Eighth Edition
• The process of acquiring the traits of one’s
predecessors
• Example
– A door with a stained glass window inherits all the
attributes (doorknob, hinges) and methods (open and
close) of a door
• Once you create an object
– Develop new objects that possess all the traits of the
original object
– Plus new traits
Encapsulation
11Programming Logic and Design, Eighth Edition
• The process of combining all of an object’s
attributes and methods into a single package
• Information hiding (also called data hiding)
– Other classes should not alter an object’s attributes
• Outside classes should only be allowed to make a
request that an attribute be altered
– It is up to the class’s methods to determine whether the
request is appropriate
Defining Classes and Creating
Class Diagrams
12Programming Logic and Design, Eighth Edition
• Class definition
– A set of program statements
– Characteristics of the class’s objects and the methods
that can be applied to its objects
• Three parts:
– Every class has a name
– Most classes contain data (not required)
– Most classes contain methods (not required)
Defining Classes and Creating
Class Diagrams (continued)
13Programming Logic and Design, Eighth Edition
• Declaring a class
– Does not create any actual objects
• After an object is instantiated
– Methods can be accessed using an identifier, a dot, and a
method call
– myAssistant.setHourlyWage(16.75)
• Employee myAssistant
– Declare the myAssistant object
– Contains all the data fields
– Access to all methods contained within the class
Defining Classes and Creating
Class Diagrams (continued)
14Programming Logic and Design, Eighth Edition
Figure 10-4 Application that declares and uses an Employee object
Defining Classes and Creating
Class Diagrams (continued)
15Programming Logic and Design, Eighth Edition
• Programmers call the classes they write user-
defined types
– More accurately called programmer-defined types
– OOP programmers call them abstract data types (ADTs)
– Simple numbers and characters are called primitive data
types
• “Black box”
– The ability to use methods without knowing the details of
their contents
– A feature of encapsulation
Creating Class Diagrams
16Programming Logic and Design, Eighth Edition
• Class diagram
– Three sections
• Top: contains the name of the class
• Middle: contains the names and data types of the attributes
• Bottom: contains the methods
Figure 10-6 Employee class diagram
17Programming Logic and Design, Eighth Edition
Figure 10-7 Pseudocode for Employee class described in the class diagram in Figure 10-6
Creating Class
Diagrams (continued)
18Programming Logic and Design, Eighth Edition
Creating Class Diagrams (continued)
• Purpose of Employee class methods
– Two of the methods accept values from the outside world
– Three of the methods send data to the outside world
– One method performs work within the class
19Programming Logic and Design, Eighth Edition
The Set Methods
• Set method (also called mutator method)
– Sets the values of data fields within the class
void setLastName(string name)
lastName = name
return
mySecretary.setLastName("Johnson")
– No requirement that such methods start with the set
prefix
– Some languages allow you to create a property to set
field values instead of creating a set method
20Programming Logic and Design, Eighth Edition
Figure 10-8 More complex setHourlyWage() method
The Set Methods (continued)
21Programming Logic and Design, Eighth Edition
The Get Methods
• Get method (also called accessor method)
• Purpose is to return a value to the world outside the
class
string getLastName()
return lastName
• Value returned from a get method can be used as
any other variable of its type would be used
22Programming Logic and Design, Eighth Edition
void calculateWeeklyPay()
Declarations
num WORK_WEEK_HOURS = 40
weeklyPay = hourlyWage * WORK_WEEK_HOURS
return
Work Methods
23Programming Logic and Design, Eighth Edition
Figure 10-9 Program that sets and displays Employee data two times
Work Methods (continued)
24Programming Logic and Design, Eighth Edition
Understanding Public and Private
Access
• You do not want any outside programs or methods
to alter your class’s data fields unless you have
control over the process
• Prevent outsiders from changing your data
– Force other programs and methods to use a method that
is part of the class
• Specify that data fields have private access
– Data cannot be accessed by any method that is not part
of the class
25Programming Logic and Design, Eighth Edition
Understanding Public and Private
Access (continued)
• Public access
– Other programs and methods may use the methods that
control access to the private data
• Access specifier
– Also called an access modifier
– An adjective defining the type of access that outside
classes will have to the attribute or method
• public or private
26Programming Logic and Design, Eighth Edition
Figure 10-11 Employee class including public and private access specifiers
Understanding Public and Private
Access (continued)
27Programming Logic and Design, Eighth Edition
• Don’t do it:
– myAssistant.hourlyWage = 15.00
• Instead:
– myAssistant.setHourlyWage(15.00)
• Methods may be private; don’t do it:
– myAssistant.calculateWeeklyPay()
Understanding Public and Private
Access (continued)
28Programming Logic and Design, Eighth Edition
Figure 10-12 Employee class diagram with public and private access specifiers
Understanding Public and Private
Access (continued)
Organizing Classes
29Programming Logic and Design, Eighth Edition
• Most programmers place data fields in logical order
at the beginning of a class
– An ID number is most likely used as a unique identifier
• Primary key
– Flexibility in how you position data fields
• In some languages, you can organize a class’s data
fields and methods in any order
30Programming Logic and Design, Eighth Edition
• Class method ordering
– Alphabetical
– Pairs of get and set methods
– Same order as the data fields are defined
– All accessor (get) methods together and all mutator (set)
methods together
Organizing Classes (continued)
Understanding Instance Methods
31Programming Logic and Design, Eighth Edition
• Every object that is an instance of a class is assumed
to possess the same data and have access to the
same methods
32Programming Logic and Design, Eighth Edition
Figure 10-13 Class diagram for
Student class
Figure 10-14 Pseudocode for the
Student class
Understanding Instance Methods
(continued)
Understanding Instance Methods
(continued)
33Programming Logic and Design, Eighth Edition
• Instance method
– Operates correctly yet differently for each separate
instance of the Student
– If you create 100 Students and assign grade point
averages to each of them, you would need 100 storage
locations in computer memory
• Only one copy of each instance method is stored in
memory
– The computer needs a way to determine whose
gradePointAverage is being set or retrieved
34Programming Logic and Design, Eighth Edition
Figure 10-16 How Student addresses are passed from an application to an instance
method of the Student class
Understanding
Instance
Methods (continued)
Understanding Instance Methods
(continued)
35Programming Logic and Design, Eighth Edition
• this reference
– An automatically created variable
– Holds the address of an object
– Passes it to an instance method whenever the method is
called
– Refers to “this particular object” using the method
– Implicitly passed as a parameter to each instance method
Understanding Instance Methods
(continued)
36Programming Logic and Design, Eighth Edition
• Identifiers within the method always mean exactly
the same thing
– Any field name
– this, followed by a dot, followed by the same field
name
• Example of an occasion when you might use the
this reference explicitly
Understanding Instance Methods
(continued)
37Programming Logic and Design, Eighth Edition
Figure 10-17 Explicitly using this in the Student class
Understanding Static Methods
38Programming Logic and Design, Eighth Edition
• Some methods do not require a this reference
• displayStudentMotto()
– A class method instead of an instance method
• Two types of methods
– Static methods (also called class methods)
• Methods for which no object needs to exist
– Nonstatic methods
• Methods that exist to be used with an object
• Student.displayStudentMotto()
Understanding Static Methods (continued)
39Programming Logic and Design, Eighth Edition
Figure 10-18 Student class displayStudentMotto() method
Using Objects
40Programming Logic and Design, Eighth Edition
• You can use objects like you would use any other
simpler data type
• InventoryItem class
– Pass to method
– Return from method
Using Objects (continued)
41Programming Logic and Design, Eighth Edition
Figure 10-19 InventoryItem class
Using Objects (continued)
42Programming Logic and Design, Eighth Edition
Figure 10-20 Application that declares and uses an InventoryItem object
43Programming Logic and Design, Eighth Edition
Figure 10-22 Application that uses InventoryItem objects
Figure 10-23 Typical execution of
program in Figure 10-22
Summary
44Programming Logic and Design, Eighth Edition
• Classes
– Basic building blocks of object-oriented programming
• Class definition
– A set of program statements that tell you the
characteristics of the class’s objects and the methods that
can be applied to its objects
• Object-oriented programmers
– Specify that their data fields will have private access
Summary (continued)
45Programming Logic and Design, Eighth Edition
• As classes get bigger, organizing becomes more
important
• Instance method
– Operates correctly yet differently for every object
instantiated from a class
• this reference
• Static methods
– Do not require a this reference

More Related Content

What's hot

CIS110 Computer Programming Design Chapter (7)
CIS110 Computer Programming Design Chapter  (7)CIS110 Computer Programming Design Chapter  (7)
CIS110 Computer Programming Design Chapter (7)Dr. Ahmed Al Zaidy
 
CIS110 Computer Programming Design Chapter (6)
CIS110 Computer Programming Design Chapter  (6)CIS110 Computer Programming Design Chapter  (6)
CIS110 Computer Programming Design Chapter (6)Dr. Ahmed Al Zaidy
 
Requirement Analysis
Requirement AnalysisRequirement Analysis
Requirement AnalysisSADEED AMEEN
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)Dr. Ahmed Al Zaidy
 
Oose unit 1 ppt
Oose unit 1 pptOose unit 1 ppt
Oose unit 1 pptDr VISU P
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programmingMakerere university
 
Software Engineering (Software Process: A Generic View)
Software Engineering (Software Process: A Generic View)Software Engineering (Software Process: A Generic View)
Software Engineering (Software Process: A Generic View)ShudipPal
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)Dr. Ahmed Al Zaidy
 
Unit 1 defects classes
Unit 1 defects classesUnit 1 defects classes
Unit 1 defects classesRoselin Mary S
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonPriyankaC44
 
Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life CycleSlideshare
 
Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)ShudipPal
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-cteach4uin
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 

What's hot (20)

Unit 5 st ppt
Unit 5 st pptUnit 5 st ppt
Unit 5 st ppt
 
CIS110 Computer Programming Design Chapter (7)
CIS110 Computer Programming Design Chapter  (7)CIS110 Computer Programming Design Chapter  (7)
CIS110 Computer Programming Design Chapter (7)
 
CIS110 Computer Programming Design Chapter (6)
CIS110 Computer Programming Design Chapter  (6)CIS110 Computer Programming Design Chapter  (6)
CIS110 Computer Programming Design Chapter (6)
 
C material
C materialC material
C material
 
Requirement Analysis
Requirement AnalysisRequirement Analysis
Requirement Analysis
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
 
User interface design
User interface designUser interface design
User interface design
 
COCOMO Model By Dr. B. J. Mohite
COCOMO Model By Dr. B. J. MohiteCOCOMO Model By Dr. B. J. Mohite
COCOMO Model By Dr. B. J. Mohite
 
Oose unit 1 ppt
Oose unit 1 pptOose unit 1 ppt
Oose unit 1 ppt
 
Examinable Question and answer system programming
Examinable Question and answer system programmingExaminable Question and answer system programming
Examinable Question and answer system programming
 
Software Engineering (Software Process: A Generic View)
Software Engineering (Software Process: A Generic View)Software Engineering (Software Process: A Generic View)
Software Engineering (Software Process: A Generic View)
 
CIS110 Computer Programming Design Chapter (3)
CIS110 Computer Programming Design Chapter  (3)CIS110 Computer Programming Design Chapter  (3)
CIS110 Computer Programming Design Chapter (3)
 
Unit 1 defects classes
Unit 1 defects classesUnit 1 defects classes
Unit 1 defects classes
 
Software quality assurance
Software quality assuranceSoftware quality assurance
Software quality assurance
 
Introduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- PythonIntroduction to Problem Solving Techniques- Python
Introduction to Problem Solving Techniques- Python
 
Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)Software Engineering (Project Scheduling)
Software Engineering (Project Scheduling)
 
3 data-types-in-c
3 data-types-in-c3 data-types-in-c
3 data-types-in-c
 
Slides chapter 2
Slides chapter 2Slides chapter 2
Slides chapter 2
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 

Viewers also liked

Rencontres de l'eau 2015
Rencontres de l'eau   2015Rencontres de l'eau   2015
Rencontres de l'eau 2015Thomas Redoulez
 
Midia Kit - Publicitários Criativos
Midia Kit - Publicitários CriativosMidia Kit - Publicitários Criativos
Midia Kit - Publicitários CriativosFillipe Luis
 
Le papillon de 3 nuits par stan
Le papillon de 3 nuits par stanLe papillon de 3 nuits par stan
Le papillon de 3 nuits par stanlfiduras
 
Odv oracle customer_demo
Odv oracle customer_demoOdv oracle customer_demo
Odv oracle customer_demoViaggio Italia
 
Robotics-Based Learning in the Context of Computer Programming
Robotics-Based Learning in the Context of Computer ProgrammingRobotics-Based Learning in the Context of Computer Programming
Robotics-Based Learning in the Context of Computer ProgrammingJacob Storer
 
Utilizing Web-based programming learning environment in University teaching
Utilizing Web-based programming learning environment in University teachingUtilizing Web-based programming learning environment in University teaching
Utilizing Web-based programming learning environment in University teachingViope Solutions Ltd
 
Machine Learning in Computer Chess: Genetic Programming and KRK
Machine Learning in Computer Chess: Genetic Programming and KRKMachine Learning in Computer Chess: Genetic Programming and KRK
Machine Learning in Computer Chess: Genetic Programming and KRKbutest
 
CIS110 Computer Programming Design Chapter (8)
CIS110 Computer Programming Design Chapter  (8)CIS110 Computer Programming Design Chapter  (8)
CIS110 Computer Programming Design Chapter (8)Dr. Ahmed Al Zaidy
 
Teaching of computer programming
Teaching of  computer programmingTeaching of  computer programming
Teaching of computer programmingmarpasha
 
Fabrizio Allegretto: Open Data & University
Fabrizio Allegretto: Open Data & UniversityFabrizio Allegretto: Open Data & University
Fabrizio Allegretto: Open Data & UniversityCarlo Vaccari
 
Intro to Computer Programming and Games Design
Intro to Computer Programming and Games DesignIntro to Computer Programming and Games Design
Intro to Computer Programming and Games DesignIan Simpson
 

Viewers also liked (13)

Rencontres de l'eau 2015
Rencontres de l'eau   2015Rencontres de l'eau   2015
Rencontres de l'eau 2015
 
Midia Kit - Publicitários Criativos
Midia Kit - Publicitários CriativosMidia Kit - Publicitários Criativos
Midia Kit - Publicitários Criativos
 
Le papillon de 3 nuits par stan
Le papillon de 3 nuits par stanLe papillon de 3 nuits par stan
Le papillon de 3 nuits par stan
 
Odv oracle customer_demo
Odv oracle customer_demoOdv oracle customer_demo
Odv oracle customer_demo
 
Über den Lebenszyklus von Forschungsdaten - Angebote und Empfehlungen von IANUS
Über den Lebenszyklus von Forschungsdaten - Angebote und Empfehlungen von IANUSÜber den Lebenszyklus von Forschungsdaten - Angebote und Empfehlungen von IANUS
Über den Lebenszyklus von Forschungsdaten - Angebote und Empfehlungen von IANUS
 
Robotics-Based Learning in the Context of Computer Programming
Robotics-Based Learning in the Context of Computer ProgrammingRobotics-Based Learning in the Context of Computer Programming
Robotics-Based Learning in the Context of Computer Programming
 
Utilizing Web-based programming learning environment in University teaching
Utilizing Web-based programming learning environment in University teachingUtilizing Web-based programming learning environment in University teaching
Utilizing Web-based programming learning environment in University teaching
 
Machine Learning in Computer Chess: Genetic Programming and KRK
Machine Learning in Computer Chess: Genetic Programming and KRKMachine Learning in Computer Chess: Genetic Programming and KRK
Machine Learning in Computer Chess: Genetic Programming and KRK
 
CIS110 Computer Programming Design Chapter (8)
CIS110 Computer Programming Design Chapter  (8)CIS110 Computer Programming Design Chapter  (8)
CIS110 Computer Programming Design Chapter (8)
 
Teaching of computer programming
Teaching of  computer programmingTeaching of  computer programming
Teaching of computer programming
 
Fabrizio Allegretto: Open Data & University
Fabrizio Allegretto: Open Data & UniversityFabrizio Allegretto: Open Data & University
Fabrizio Allegretto: Open Data & University
 
Intro to Computer Programming and Games Design
Intro to Computer Programming and Games DesignIntro to Computer Programming and Games Design
Intro to Computer Programming and Games Design
 
Sql9e ppt ch04
Sql9e ppt ch04 Sql9e ppt ch04
Sql9e ppt ch04
 

Similar to CIS110 Computer Programming Design Chapter (10)

CIS110 Computer Programming Design Chapter (11)
CIS110 Computer Programming Design Chapter  (11)CIS110 Computer Programming Design Chapter  (11)
CIS110 Computer Programming Design Chapter (11)Dr. Ahmed Al Zaidy
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Nicole Ryan
 
Object-Oriented Design Fundamentals.pptx
Object-Oriented Design Fundamentals.pptxObject-Oriented Design Fundamentals.pptx
Object-Oriented Design Fundamentals.pptxRaflyRizky2
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.pptYonas D. Ebren
 
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
 
Chapter 6 Object Modeling .pptxInformation Technology Project Management
Chapter 6 Object Modeling .pptxInformation Technology Project ManagementChapter 6 Object Modeling .pptxInformation Technology Project Management
Chapter 6 Object Modeling .pptxInformation Technology Project ManagementAxmedMaxamuudYoonis
 
chapter06-120827115400-phpapp01.pdf
chapter06-120827115400-phpapp01.pdfchapter06-120827115400-phpapp01.pdf
chapter06-120827115400-phpapp01.pdfAxmedMaxamuud6
 
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
 
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxsaber tabatabaee
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#SyedUmairAli9
 

Similar to CIS110 Computer Programming Design Chapter (10) (20)

CIS110 Computer Programming Design Chapter (11)
CIS110 Computer Programming Design Chapter  (11)CIS110 Computer Programming Design Chapter  (11)
CIS110 Computer Programming Design Chapter (11)
 
Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2Chapter 11: Object Oriented Programming Part 2
Chapter 11: Object Oriented Programming Part 2
 
Object-Oriented Design Fundamentals.pptx
Object-Oriented Design Fundamentals.pptxObject-Oriented Design Fundamentals.pptx
Object-Oriented Design Fundamentals.pptx
 
Chap01
Chap01Chap01
Chap01
 
02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt02._Object-Oriented_Programming_Concepts.ppt
02._Object-Oriented_Programming_Concepts.ppt
 
Ch03
Ch03Ch03
Ch03
 
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
 
Chapter 6 Object Modeling .pptxInformation Technology Project Management
Chapter 6 Object Modeling .pptxInformation Technology Project ManagementChapter 6 Object Modeling .pptxInformation Technology Project Management
Chapter 6 Object Modeling .pptxInformation Technology Project Management
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
OOP Presentation.pptx
OOP Presentation.pptxOOP Presentation.pptx
OOP Presentation.pptx
 
chapter06-120827115400-phpapp01.pdf
chapter06-120827115400-phpapp01.pdfchapter06-120827115400-phpapp01.pdf
chapter06-120827115400-phpapp01.pdf
 
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
 
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptxclean architecture uncle bob AnalysisAndDesign.el.en.pptx
clean architecture uncle bob AnalysisAndDesign.el.en.pptx
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
 

More from Dr. Ahmed Al Zaidy

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingDr. Ahmed Al Zaidy
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web formsDr. Ahmed Al Zaidy
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsDr. Ahmed Al Zaidy
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesDr. Ahmed Al Zaidy
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsDr. Ahmed Al Zaidy
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptDr. Ahmed Al Zaidy
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaDr. Ahmed Al Zaidy
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web formDr. Ahmed Al Zaidy
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsDr. Ahmed Al Zaidy
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webDr. Ahmed Al Zaidy
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSDr. Ahmed Al Zaidy
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutDr. Ahmed Al Zaidy
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSDr. Ahmed Al Zaidy
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Dr. Ahmed Al Zaidy
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2Dr. Ahmed Al Zaidy
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business ContinuityDr. Ahmed Al Zaidy
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityDr. Ahmed Al Zaidy
 

More from Dr. Ahmed Al Zaidy (20)

Chapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based ProgrammingChapter 14 Exploring Object-based Programming
Chapter 14 Exploring Object-based Programming
 
Chapter 13 Programming for web forms
Chapter 13 Programming for web formsChapter 13 Programming for web forms
Chapter 13 Programming for web forms
 
Chapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheetsChapter 12 Working with Document nodes and style sheets
Chapter 12 Working with Document nodes and style sheets
 
Chapter 11 Working with Events and Styles
Chapter 11 Working with Events and StylesChapter 11 Working with Events and Styles
Chapter 11 Working with Events and Styles
 
Chapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statementsChapter 10 Exploring arrays, loops, and conditional statements
Chapter 10 Exploring arrays, loops, and conditional statements
 
Chapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScriptChapter 9 Getting Started with JavaScript
Chapter 9 Getting Started with JavaScript
 
Chapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimediaChapter 8 Enhancing a website with multimedia
Chapter 8 Enhancing a website with multimedia
 
Chapter 7 Designing a web form
Chapter 7 Designing a web formChapter 7 Designing a web form
Chapter 7 Designing a web form
 
Chapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and ColumnsChapter 6 Working with Tables and Columns
Chapter 6 Working with Tables and Columns
 
Chapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile webChapter 5 Designing for the mobile web
Chapter 5 Designing for the mobile web
 
Chapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSSChapter 4 Graphic Design with CSS
Chapter 4 Graphic Design with CSS
 
Chapter 3 Designing a Page Layout
Chapter 3 Designing a Page LayoutChapter 3 Designing a Page Layout
Chapter 3 Designing a Page Layout
 
Chapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSSChapter 2 Getting Started with CSS
Chapter 2 Getting Started with CSS
 
Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5Chapter 1 Getting Started with HTML5
Chapter 1 Getting Started with HTML5
 
Integer overflows
Integer overflowsInteger overflows
Integer overflows
 
testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2testing throughout-the-software-life-cycle-section-2
testing throughout-the-software-life-cycle-section-2
 
Fundamental of testing
Fundamental of testingFundamental of testing
Fundamental of testing
 
Chapter 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk Mitigation
 
Chapter 14 Business Continuity
Chapter 14 Business ContinuityChapter 14 Business Continuity
Chapter 14 Business Continuity
 
Chapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data SecurityChapter 13 Vulnerability Assessment and Data Security
Chapter 13 Vulnerability Assessment and Data Security
 

Recently uploaded

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 

Recently uploaded (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 

CIS110 Computer Programming Design Chapter (10)

  • 1. Programming Logic and Design Eighth Edition Chapter 10 Object-Oriented Programming
  • 2. Objectives In this chapter, you will learn about: • The principles of object-oriented programming • Classes • Public and private access • Ways to organize classes • Instance methods • Static methods • Using objects 2Programming Logic and Design, Eighth Edition
  • 3. Principles of Object-Oriented Programming 3Programming Logic and Design, Eighth Edition • Object-oriented programming (OOP) – A style of programming that focuses on an application’s data and the methods to manipulate that data • Uses all of the familiar concepts from modular procedural programming – Variables, methods, passing arguments – Sequence, selection, and looping structures – But involves a different way of thinking
  • 4. Principles of Object-Oriented Programming (continued) 4Programming Logic and Design, Eighth Edition • Important features of object-oriented languages – Classes – Objects – Polymorphism – Inheritance – Encapsulation
  • 5. 5Programming Logic and Design, Eighth Edition Classes and Objects • Class – Describes a group or collection of objects with common attributes • Object - One instance of a class – Sometimes called one instantiation of a class – When a program creates an object, it instantiates the object • Example – Class name: dog – Attributes: name, age, hasShots – Methods: changeName, updateShots
  • 6. Classes and Objects (continued) 6Programming Logic and Design, Eighth Edition • Attributes – Characteristics that define an object as part of a class – Example • Automobile’s attributes: make, model, year, and purchase price • Methods – Actions that alter, use, or retrieve the attributes – Example • Methods for changing an automobile’s running status, gear, speed, and cleanliness
  • 7. Classes and Objects (continued) 7Programming Logic and Design, Eighth Edition • Think in an object-oriented manner – Everything is an object – Every object is a member of a class • Is-a relationship – “My oak desk with the scratch on top is a Desk” • Class reusability • Class’s instance variables – Data components of a class that belong to every instantiated object – Often called fields
  • 8. Classes and Objects (continued) 8Programming Logic and Design, Eighth Edition • State – A set of all the values or contents of a class object’s instance variables • Every object that is an instance of a class possesses the same methods • Create classes from which objects will be instantiated • Class client or class user – A program or class that instantiates objects of another prewritten class
  • 9. Polymorphism 9Programming Logic and Design, Eighth Edition • The world is full of objects – A door is an object that needs to be open or closed – But an “open” procedure works differently on different objects • Open a door • Open a drawer • Open a bank account • Open a file • Open your eyes – One “open” procedure can open anything if it gets the correct arguments
  • 10. Inheritance 10Programming Logic and Design, Eighth Edition • The process of acquiring the traits of one’s predecessors • Example – A door with a stained glass window inherits all the attributes (doorknob, hinges) and methods (open and close) of a door • Once you create an object – Develop new objects that possess all the traits of the original object – Plus new traits
  • 11. Encapsulation 11Programming Logic and Design, Eighth Edition • The process of combining all of an object’s attributes and methods into a single package • Information hiding (also called data hiding) – Other classes should not alter an object’s attributes • Outside classes should only be allowed to make a request that an attribute be altered – It is up to the class’s methods to determine whether the request is appropriate
  • 12. Defining Classes and Creating Class Diagrams 12Programming Logic and Design, Eighth Edition • Class definition – A set of program statements – Characteristics of the class’s objects and the methods that can be applied to its objects • Three parts: – Every class has a name – Most classes contain data (not required) – Most classes contain methods (not required)
  • 13. Defining Classes and Creating Class Diagrams (continued) 13Programming Logic and Design, Eighth Edition • Declaring a class – Does not create any actual objects • After an object is instantiated – Methods can be accessed using an identifier, a dot, and a method call – myAssistant.setHourlyWage(16.75) • Employee myAssistant – Declare the myAssistant object – Contains all the data fields – Access to all methods contained within the class
  • 14. Defining Classes and Creating Class Diagrams (continued) 14Programming Logic and Design, Eighth Edition Figure 10-4 Application that declares and uses an Employee object
  • 15. Defining Classes and Creating Class Diagrams (continued) 15Programming Logic and Design, Eighth Edition • Programmers call the classes they write user- defined types – More accurately called programmer-defined types – OOP programmers call them abstract data types (ADTs) – Simple numbers and characters are called primitive data types • “Black box” – The ability to use methods without knowing the details of their contents – A feature of encapsulation
  • 16. Creating Class Diagrams 16Programming Logic and Design, Eighth Edition • Class diagram – Three sections • Top: contains the name of the class • Middle: contains the names and data types of the attributes • Bottom: contains the methods Figure 10-6 Employee class diagram
  • 17. 17Programming Logic and Design, Eighth Edition Figure 10-7 Pseudocode for Employee class described in the class diagram in Figure 10-6 Creating Class Diagrams (continued)
  • 18. 18Programming Logic and Design, Eighth Edition Creating Class Diagrams (continued) • Purpose of Employee class methods – Two of the methods accept values from the outside world – Three of the methods send data to the outside world – One method performs work within the class
  • 19. 19Programming Logic and Design, Eighth Edition The Set Methods • Set method (also called mutator method) – Sets the values of data fields within the class void setLastName(string name) lastName = name return mySecretary.setLastName("Johnson") – No requirement that such methods start with the set prefix – Some languages allow you to create a property to set field values instead of creating a set method
  • 20. 20Programming Logic and Design, Eighth Edition Figure 10-8 More complex setHourlyWage() method The Set Methods (continued)
  • 21. 21Programming Logic and Design, Eighth Edition The Get Methods • Get method (also called accessor method) • Purpose is to return a value to the world outside the class string getLastName() return lastName • Value returned from a get method can be used as any other variable of its type would be used
  • 22. 22Programming Logic and Design, Eighth Edition void calculateWeeklyPay() Declarations num WORK_WEEK_HOURS = 40 weeklyPay = hourlyWage * WORK_WEEK_HOURS return Work Methods
  • 23. 23Programming Logic and Design, Eighth Edition Figure 10-9 Program that sets and displays Employee data two times Work Methods (continued)
  • 24. 24Programming Logic and Design, Eighth Edition Understanding Public and Private Access • You do not want any outside programs or methods to alter your class’s data fields unless you have control over the process • Prevent outsiders from changing your data – Force other programs and methods to use a method that is part of the class • Specify that data fields have private access – Data cannot be accessed by any method that is not part of the class
  • 25. 25Programming Logic and Design, Eighth Edition Understanding Public and Private Access (continued) • Public access – Other programs and methods may use the methods that control access to the private data • Access specifier – Also called an access modifier – An adjective defining the type of access that outside classes will have to the attribute or method • public or private
  • 26. 26Programming Logic and Design, Eighth Edition Figure 10-11 Employee class including public and private access specifiers Understanding Public and Private Access (continued)
  • 27. 27Programming Logic and Design, Eighth Edition • Don’t do it: – myAssistant.hourlyWage = 15.00 • Instead: – myAssistant.setHourlyWage(15.00) • Methods may be private; don’t do it: – myAssistant.calculateWeeklyPay() Understanding Public and Private Access (continued)
  • 28. 28Programming Logic and Design, Eighth Edition Figure 10-12 Employee class diagram with public and private access specifiers Understanding Public and Private Access (continued)
  • 29. Organizing Classes 29Programming Logic and Design, Eighth Edition • Most programmers place data fields in logical order at the beginning of a class – An ID number is most likely used as a unique identifier • Primary key – Flexibility in how you position data fields • In some languages, you can organize a class’s data fields and methods in any order
  • 30. 30Programming Logic and Design, Eighth Edition • Class method ordering – Alphabetical – Pairs of get and set methods – Same order as the data fields are defined – All accessor (get) methods together and all mutator (set) methods together Organizing Classes (continued)
  • 31. Understanding Instance Methods 31Programming Logic and Design, Eighth Edition • Every object that is an instance of a class is assumed to possess the same data and have access to the same methods
  • 32. 32Programming Logic and Design, Eighth Edition Figure 10-13 Class diagram for Student class Figure 10-14 Pseudocode for the Student class Understanding Instance Methods (continued)
  • 33. Understanding Instance Methods (continued) 33Programming Logic and Design, Eighth Edition • Instance method – Operates correctly yet differently for each separate instance of the Student – If you create 100 Students and assign grade point averages to each of them, you would need 100 storage locations in computer memory • Only one copy of each instance method is stored in memory – The computer needs a way to determine whose gradePointAverage is being set or retrieved
  • 34. 34Programming Logic and Design, Eighth Edition Figure 10-16 How Student addresses are passed from an application to an instance method of the Student class Understanding Instance Methods (continued)
  • 35. Understanding Instance Methods (continued) 35Programming Logic and Design, Eighth Edition • this reference – An automatically created variable – Holds the address of an object – Passes it to an instance method whenever the method is called – Refers to “this particular object” using the method – Implicitly passed as a parameter to each instance method
  • 36. Understanding Instance Methods (continued) 36Programming Logic and Design, Eighth Edition • Identifiers within the method always mean exactly the same thing – Any field name – this, followed by a dot, followed by the same field name • Example of an occasion when you might use the this reference explicitly
  • 37. Understanding Instance Methods (continued) 37Programming Logic and Design, Eighth Edition Figure 10-17 Explicitly using this in the Student class
  • 38. Understanding Static Methods 38Programming Logic and Design, Eighth Edition • Some methods do not require a this reference • displayStudentMotto() – A class method instead of an instance method • Two types of methods – Static methods (also called class methods) • Methods for which no object needs to exist – Nonstatic methods • Methods that exist to be used with an object • Student.displayStudentMotto()
  • 39. Understanding Static Methods (continued) 39Programming Logic and Design, Eighth Edition Figure 10-18 Student class displayStudentMotto() method
  • 40. Using Objects 40Programming Logic and Design, Eighth Edition • You can use objects like you would use any other simpler data type • InventoryItem class – Pass to method – Return from method
  • 41. Using Objects (continued) 41Programming Logic and Design, Eighth Edition Figure 10-19 InventoryItem class
  • 42. Using Objects (continued) 42Programming Logic and Design, Eighth Edition Figure 10-20 Application that declares and uses an InventoryItem object
  • 43. 43Programming Logic and Design, Eighth Edition Figure 10-22 Application that uses InventoryItem objects Figure 10-23 Typical execution of program in Figure 10-22
  • 44. Summary 44Programming Logic and Design, Eighth Edition • Classes – Basic building blocks of object-oriented programming • Class definition – A set of program statements that tell you the characteristics of the class’s objects and the methods that can be applied to its objects • Object-oriented programmers – Specify that their data fields will have private access
  • 45. Summary (continued) 45Programming Logic and Design, Eighth Edition • As classes get bigger, organizing becomes more important • Instance method – Operates correctly yet differently for every object instantiated from a class • this reference • Static methods – Do not require a this reference