SlideShare a Scribd company logo
Object-Oriented
Programming and
Classes
Chapter 7
7
Refactoring
Classes should perform one task.
If a class performs multiple tasks, it
should be refactored into two or more
classes.
This process is analogous to factoring
composite numbers into their primes.
7
Setting State
An object uses member variables to
keep track of its own state.
The Ball object knows its own:
x and y location
x and y velocity
7
Implementing Methods
The Ball class is responsible for:
Moving itself
Drawing itself
The World does the following:
Erases the ball
Moves the ball
Checks for ball collision and changes the
ball velocity, if necessary
Draws the ball
7
Encapsulating Responsibility
A class should be responsible for its own
behavior.
Encapsulation makes programs easier to
maintain and expand.
It is easier to reuse encapsulated classes
in other programs.
7
ProgramDesign Considerations
Good software design requires planning,
evaluation, and conscious implementation
decisions.
Symptoms of poor program design:
Many small, data-only objects and one large,
controlling object that makes everything happen
Objects that need to know a lot of details about
another object’s implementation
7
Method Overloading
Creating more than one version of a
method with different parameter lists
Compiler decides which method to use
based on method signature.
Number of parameters
Order of parameters
Type of parameters
Overloading provides “optional”
arguments.
7
Overloading Constructors
Constructor methods are used when
an object is instantiated.
Overloaded constructors provide optional
ways of creating objects.
7
Putting It All Together
Ball class overloaded to
permit clients to create
different size Ball
objects
HWall class overloaded
to allow clients to specify
elasticity
7
Putting It All Together
Ball class overloaded to
permit clients to create
different size Ball
objects
HWall class overloaded
to allow clients to specify
elasticity

More Related Content

Similar to Chapter 07

Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
farhan amjad
 
OODJ-MODULE 1.pptx
OODJ-MODULE 1.pptxOODJ-MODULE 1.pptx
OODJ-MODULE 1.pptx
SharaneshUpase1
 
Testing method pptx
Testing method pptxTesting method pptx
Testing method pptx
02LabiqaIslam
 
Software enginneering
Software enginneeringSoftware enginneering
Software enginneering
chirag patil
 
CSCI-383 Lecture 5-6-7: Object-Oriented Design
CSCI-383 Lecture 5-6-7: Object-Oriented DesignCSCI-383 Lecture 5-6-7: Object-Oriented Design
CSCI-383 Lecture 5-6-7: Object-Oriented Design
JI Ruan
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
floraaluoch3
 
1. oop with c++ get 410 day 1
1. oop with c++ get 410   day 11. oop with c++ get 410   day 1
1. oop with c++ get 410 day 1
Mukul kumar Neal
 
Se chapter 1,2,3 2 mark qa
Se chapter 1,2,3   2 mark  qaSe chapter 1,2,3   2 mark  qa
Se chapter 1,2,3 2 mark qa
Aruna M
 
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkkSWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
erenakarsu1
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
Deborah Akuoko
 
Ch7
Ch7Ch7
unit - 2 - software engineer practices.ppt
unit - 2 - software engineer practices.pptunit - 2 - software engineer practices.ppt
unit - 2 - software engineer practices.ppt
Chaitanyabenade
 
1989 Joyce: An Object-Oriented Decision Tree Builder
1989 Joyce: An Object-Oriented Decision Tree Builder1989 Joyce: An Object-Oriented Decision Tree Builder
1989 Joyce: An Object-Oriented Decision Tree Builder
Bob Marcus
 
Joyce: An Object-oriented Decision Tree Builder 1989
Joyce: An Object-oriented Decision Tree Builder 1989Joyce: An Object-oriented Decision Tree Builder 1989
Joyce: An Object-oriented Decision Tree Builder 1989
Bob Marcus
 
Ch 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptxCh 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptx
MahiDivya
 
Chapter Six: Design and impelementation.
Chapter Six: Design and impelementation.Chapter Six: Design and impelementation.
Chapter Six: Design and impelementation.
AbdikariimShiekhabdi
 
OO Development 1 - Introduction to Object-Oriented Development
OO Development 1 - Introduction to Object-Oriented DevelopmentOO Development 1 - Introduction to Object-Oriented Development
OO Development 1 - Introduction to Object-Oriented Development
Randy Connolly
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptx
ArifaMehreen1
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
info_zybotech
 
Creating a Use Case
Creating a Use Case                                               Creating a Use Case
Creating a Use Case
CruzIbarra161
 

Similar to Chapter 07 (20)

Introduction to object oriented language
Introduction to object oriented languageIntroduction to object oriented language
Introduction to object oriented language
 
OODJ-MODULE 1.pptx
OODJ-MODULE 1.pptxOODJ-MODULE 1.pptx
OODJ-MODULE 1.pptx
 
Testing method pptx
Testing method pptxTesting method pptx
Testing method pptx
 
Software enginneering
Software enginneeringSoftware enginneering
Software enginneering
 
CSCI-383 Lecture 5-6-7: Object-Oriented Design
CSCI-383 Lecture 5-6-7: Object-Oriented DesignCSCI-383 Lecture 5-6-7: Object-Oriented Design
CSCI-383 Lecture 5-6-7: Object-Oriented Design
 
DOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in cDOC-20210303-WA0017..pptx,coding stuff in c
DOC-20210303-WA0017..pptx,coding stuff in c
 
1. oop with c++ get 410 day 1
1. oop with c++ get 410   day 11. oop with c++ get 410   day 1
1. oop with c++ get 410 day 1
 
Se chapter 1,2,3 2 mark qa
Se chapter 1,2,3   2 mark  qaSe chapter 1,2,3   2 mark  qa
Se chapter 1,2,3 2 mark qa
 
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkkSWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
SWE218_lesson9.pdfjjjjjjjjjjjjjjjjjjkjkkk
 
Oop basic overview
Oop basic overviewOop basic overview
Oop basic overview
 
Ch7
Ch7Ch7
Ch7
 
unit - 2 - software engineer practices.ppt
unit - 2 - software engineer practices.pptunit - 2 - software engineer practices.ppt
unit - 2 - software engineer practices.ppt
 
1989 Joyce: An Object-Oriented Decision Tree Builder
1989 Joyce: An Object-Oriented Decision Tree Builder1989 Joyce: An Object-Oriented Decision Tree Builder
1989 Joyce: An Object-Oriented Decision Tree Builder
 
Joyce: An Object-oriented Decision Tree Builder 1989
Joyce: An Object-oriented Decision Tree Builder 1989Joyce: An Object-oriented Decision Tree Builder 1989
Joyce: An Object-oriented Decision Tree Builder 1989
 
Ch 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptxCh 1 Introduction to Object Oriented Programming.pptx
Ch 1 Introduction to Object Oriented Programming.pptx
 
Chapter Six: Design and impelementation.
Chapter Six: Design and impelementation.Chapter Six: Design and impelementation.
Chapter Six: Design and impelementation.
 
OO Development 1 - Introduction to Object-Oriented Development
OO Development 1 - Introduction to Object-Oriented DevelopmentOO Development 1 - Introduction to Object-Oriented Development
OO Development 1 - Introduction to Object-Oriented Development
 
Software_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptxSoftware_Engineering_Presentation (1).pptx
Software_Engineering_Presentation (1).pptx
 
Notepad tutorial
Notepad tutorialNotepad tutorial
Notepad tutorial
 
Creating a Use Case
Creating a Use Case                                               Creating a Use Case
Creating a Use Case
 

More from Graham Royce

Chapter 18
Chapter 18Chapter 18
Chapter 18
Graham Royce
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
Graham Royce
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
Graham Royce
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
Graham Royce
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
Graham Royce
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
Graham Royce
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
Graham Royce
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
Graham Royce
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
Graham Royce
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
Graham Royce
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
Graham Royce
 
Chapter 06
Chapter 06Chapter 06
Chapter 06
Graham Royce
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
Graham Royce
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
Graham Royce
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
Graham Royce
 
Chapter 02
Chapter 02Chapter 02
Chapter 02
Graham Royce
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
Graham Royce
 
13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
Graham Royce
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
Graham Royce
 
My 3 min pitch pack
My 3 min pitch packMy 3 min pitch pack
My 3 min pitch pack
Graham Royce
 

More from Graham Royce (20)

Chapter 18
Chapter 18Chapter 18
Chapter 18
 
Chapter 17
Chapter 17Chapter 17
Chapter 17
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Chapter 15
Chapter 15Chapter 15
Chapter 15
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
Chapter 12
Chapter 12Chapter 12
Chapter 12
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Chapter 09
Chapter 09Chapter 09
Chapter 09
 
Chapter 08
Chapter 08Chapter 08
Chapter 08
 
Chapter 06
Chapter 06Chapter 06
Chapter 06
 
Chapter 05
Chapter 05Chapter 05
Chapter 05
 
Chapter 04
Chapter 04Chapter 04
Chapter 04
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
Chapter 02
Chapter 02Chapter 02
Chapter 02
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
My 3 min pitch pack
My 3 min pitch packMy 3 min pitch pack
My 3 min pitch pack
 

Recently uploaded

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
Edge AI and Vision Alliance
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 

Recently uploaded (20)

Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024Northern Engraving | Nameplate Manufacturing Process - 2024
Northern Engraving | Nameplate Manufacturing Process - 2024
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
“Temporal Event Neural Networks: A More Efficient Alternative to the Transfor...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 

Chapter 07

  • 2. 7 Refactoring Classes should perform one task. If a class performs multiple tasks, it should be refactored into two or more classes. This process is analogous to factoring composite numbers into their primes.
  • 3. 7 Setting State An object uses member variables to keep track of its own state. The Ball object knows its own: x and y location x and y velocity
  • 4. 7 Implementing Methods The Ball class is responsible for: Moving itself Drawing itself The World does the following: Erases the ball Moves the ball Checks for ball collision and changes the ball velocity, if necessary Draws the ball
  • 5. 7 Encapsulating Responsibility A class should be responsible for its own behavior. Encapsulation makes programs easier to maintain and expand. It is easier to reuse encapsulated classes in other programs.
  • 6. 7 ProgramDesign Considerations Good software design requires planning, evaluation, and conscious implementation decisions. Symptoms of poor program design: Many small, data-only objects and one large, controlling object that makes everything happen Objects that need to know a lot of details about another object’s implementation
  • 7. 7 Method Overloading Creating more than one version of a method with different parameter lists Compiler decides which method to use based on method signature. Number of parameters Order of parameters Type of parameters Overloading provides “optional” arguments.
  • 8. 7 Overloading Constructors Constructor methods are used when an object is instantiated. Overloaded constructors provide optional ways of creating objects.
  • 9. 7 Putting It All Together Ball class overloaded to permit clients to create different size Ball objects HWall class overloaded to allow clients to specify elasticity
  • 10. 7 Putting It All Together Ball class overloaded to permit clients to create different size Ball objects HWall class overloaded to allow clients to specify elasticity