SlideShare a Scribd company logo
1 of 48
Programming Logic and Design
Eighth Edition
Chapter 9
Advanced Modularization Techniques
Objectives
In this chapter, you will learn about:
• The parts of a method
• Methods with no parameters
• Methods that require parameters
• Methods that return a value
• Passing arrays to methods
• Overloading methods
• Using predefined methods
• Method design issues, including implementation hiding,
cohesion, and coupling
• Recursion
2Programming Logic and Design, Eighth Edition
The Parts of a Method
3Programming Logic and Design, Eighth Edition
• Method
– A program module that contains a series of statements
that carry out a task
– Invoke or call a method from another program or method
– Any program can contain an unlimited number of
methods
– Each method can be called an unlimited number of times
The Parts of a Method (continued)
4Programming Logic and Design, Eighth Edition
• Method must include
– Method header (also called the declaration or definition)
– Method body
• Contains the implementation (Statements that carry out the
tasks)
– Method return statement (Returns control to the calling
method)
• Variables and constants
– Local: declared in a method
– Global: known to all program modules
5Programming Logic and Design, Eighth Edition
Figure 9-1 A program that calculates
the user’s weight on the moon
Using Methods
with No
Parameters
Figure 9-2 Output of moon weight
calculator program
Using Methods with No
Parameters (continued)
6Programming Logic and Design, Eighth Edition
• When methods must share data
– Pass the data into and return the data out of methods
• When you call a method from a program, you must
know three things:
– Name of the called method
– Type of information to send to the method, if any
– Type of return data to expect from the method, if any
Creating Methods that Require
Parameters
7Programming Logic and Design, Eighth Edition
• Argument to the method
– Pass a data item into a method from a calling program
• Parameter to the method
– Method receives the data item
• To write the declaration for a method that can
receive a parameter, you must know:
– The type of the parameter
– The local name for the parameter
Creating Methods that Require
Parameters (continued)
8Programming Logic and Design, Eighth Edition
• Parameter list
– Types and names of parameters
• Signature
– Method’s name and parameter list
Creating Methods that Require
Parameters (continued)
9Programming Logic and Design, Eighth Edition
• Improve the moon weight program by making the
final output more user-friendly
• Several approaches
– Rewrite the program without including any methods
– Retain the displayInstructions() method, but
make the langCode variable global
– Retain the displayInstructions() method as is,
but add a section to the main program that also asks the
user for a preferred language
– Store the variable that holds the language code in the
main program
Creating Methods that Require
Parameters (continued)
10Programming Logic and Design, Eighth Edition
• Passed by value
– A copy of a value is sent to the method and stored in a
new memory location accessible to the method
• Each time a method executes, parameter variables
listed in the method header are redeclared
Creating Methods that Require
Multiple Parameters
11Programming Logic and Design, Eighth Edition
• Methods can require more than one parameter
– List the arguments within the method call, separated by
commas
– List a data type and local identifier for each parameter
within the method header’s parentheses
– Separate each declaration with a comma
– The data type must be repeated with each parameter
– Arguments sent are called actual parameters
– Variables that accept the parameters in the method are
called formal parameters
12Programming Logic and Design, Eighth Edition
Figure 9-7 A program that calls a computeTax() method that requires two parameters
Creating
Methods that
Require
Multiple
Parameters (continued)
Creating Methods that Return a
Value
13Programming Logic and Design, Eighth Edition
• A variable declared within a method ceases to exist
when the method ends
– Goes out of scope
• To retain a value that exists when a method ends,
return the value from the method back to the
calling method
• When a method returns a value, the method must
have a return type that matches the data type of
the value that is returned
Creating Methods that Return a
Value (continued)
14Programming Logic and Design, Eighth Edition
• Return type for a method
– Indicates the data type of the value that the method will
send back
– Can be any type
– Also called method’s type
– Listed in front of the method name when the method is
defined
• Method can also return nothing
– Return type void
– Void method
Creating Methods that Return a
Value (continued)
15Programming Logic and Design, Eighth Edition
• Example: num getHoursWorked()
– Returns a numeric value
• Usually, you want to use the returned value in the
calling method
– Not required
– Store in variable or use directly without storing
• output "Hours worked is ", getHoursWorked()
16Programming Logic and Design, Eighth Edition
Figure 9-8 A payroll program that calls a
method that returns a value
Figure 9-9 A program that uses a method’s
returned value without storing it
Creating Methods that Return a
Value (continued)
17Programming Logic and Design, Eighth Edition
Creating Methods that Return a
Value (continued)
• Technically, you are allowed to include multiple
return statements in a method
– It’s not recommended
– Violates structured logic
18Programming Logic and Design, Eighth Edition
Creating Methods that Return a
Value (continued)
Figure 9-10 Unstructured approach to returning one of several values
19Programming Logic and Design, Eighth Edition
Figure 9-11 Recommended, structured approach to returning one of several values
Creating Methods
that Return a
Value (continued)
20Programming Logic and Design, Eighth Edition
Creating Methods that Return a
Value (continued)
• To use a method, you should know:
– What the method does in general, but not necessarily
how it carries out tasks internally
– The method’s name
– The method’s required parameters, if any
– The method’s return type, so that you can use any
returned value appropriately
21Programming Logic and Design, Eighth Edition
• IPO chart
– A tool that identifies and categorizes each item in a
method by input, processing, and output
• A method that finds the smallest of three numeric
values
Figure 9-12 IPO chart for the method that finds the smallest of three numeric values
Using an IPO Chart
22Programming Logic and Design, Eighth Edition
• Many programmers create an IPO chart only for
specific methods in their programs
• Provide an overview of:
– Input to the method
– Processing steps that must occur
– Result
Using an IPO Chart (continued)
23Programming Logic and Design, Eighth Edition
• Pass a single array element to a method
– Same manner you would pass a variable or constant
• Pass an entire array as an argument
• Indicate that a method parameter must be an array
– Place square brackets after the data type in the method’s
parameter list
• Passed by
reference
– Changes you make to
array elements within the method are permanent
Passing an Array to a Method
Figure 9-45 Output of the
PassArrayElement program
24Programming Logic and Design, Eighth Edition
Figure 9-15 PassEntireArray program
Passing an
Array to a
Method (continued)
25Programming Logic and Design, Eighth Edition
Figure 9-15 PassEntireArray program (continued)
Passing an
Array to a
Method (continued)
26Programming Logic and Design, Eighth Edition
Figure 9-15 PassEntireArray
program (continued)
Figure 9-16 Output of the
PassEntireArray program
Passing an
Array to a
Method (continued)
Overloading Methods
27Programming Logic and Design, Eighth Edition
• Overloading
– Involves supplying diverse meanings for a single identifier
– Similar to English language—the word break can be
overloaded to mean:
• Break a window
• Break bread
• Break the bank
• Take a break
• Overload a method
– Write multiple methods with a shared name but different
parameter lists
28Programming Logic and Design, Eighth Edition
• Call an overloaded method
– Language translator understands which version of the
method to use based on the arguments used
• Polymorphism
– Ability of a method to act appropriately according to the
context
– Literally, polymorphism means “many forms”
Overloading Methods (continued)
29Programming Logic and Design, Eighth Edition
Figure 9-17 Two overloaded versions of the printBill() method
Overloading Methods (continued)
30Programming Logic and Design, Eighth Edition
Figure 9-18 Two additional overloaded versions of the printBill() method
Overloading Methods (continued)
31Programming Logic and Design, Eighth Edition
• Overloading methods is never required in a program
– Could create multiple methods with unique identifiers
• Advantage is provided to your method’s clients
– Those who use your methods need to remember just one
appropriate name for all related tasks
Overloading Methods (continued)
32Programming Logic and Design, Eighth Edition
• Ambiguous methods
– Situations in which the compiler cannot determine which
method to use
• Every time you call a method
– Compiler decides whether a suitable method exists
– If so, the method executes
– If not, you receive an error message
Avoiding Ambiguous Methods
33Programming Logic and Design, Eighth Edition
Figure 9-19 Program that contains ambiguous
method call
Avoiding
Ambiguous
Methods (continued)
Avoiding Ambiguous Methods (continued)
34Programming Logic and Design, Eighth Edition
• Overload method correctly
– Different parameter lists for methods with the same
name
• Ambiguous, not overloaded
– Methods with identical names that have identical
parameter lists but different return types
– Example
string aMethod(num x)
num aMethod(num y)
Using Predefined Methods
35Programming Logic and Design, Eighth Edition
• Modern programming languages contain many
methods that have already been written
• Sources
– Built-in methods
– Program team members
– Company-wide methods and standards
• Save time and effort
• Output methods
• Mathematical methods
Using Predefined Methods (continued)
36Programming Logic and Design, Eighth Edition
• To use predefined methods, you should know:
– What the method does in general
– Name
– Required parameters
– Return type
• You do not need to know:
– How method is implemented
Method Design Issues: Implementation
Hiding, Cohesion, and Coupling
37Programming Logic and Design, Eighth Edition
• Consider several program qualities
– Employ implementation hiding
• Clients don’ t need to understand internal mechanisms
– Strive to increase cohesion
– Strive to reduce coupling
Understanding Implementation
Hiding
38Programming Logic and Design, Eighth Edition
• Implementation hiding
– Encapsulation of method details
• When a program makes a request to a method, it
does not know the details of how the method is
executed
• A method that calls another must know:
– The name of the called method
– The type of information to send to the method
– The type of return data to expect from the method
39Programming Logic and Design, Eighth Edition
• Interface to the method
– The only part of a method with which the method’s client
interacts
• Substitute a new method implementation
– As long as the interface does not change, you do not
need to make changes in any methods that call the
altered method
• A hidden implementation is often called a black box
– You can examine what goes in and out but not how it
works
Understanding Implementation
Hiding (continued)
Increasing Cohesion
40Programming Logic and Design, Eighth Edition
• It is difficult to decide how much to put into a
method
• Cohesion
– How the internal statements of a method serve to
accomplish the method’s purpose
• Highly cohesive methods
– All the operations are related
– Functionally cohesive
– Usually more reliable than those that have low cohesion
Reducing Coupling
41Programming Logic and Design, Eighth Edition
• Coupling
– A measure of the strength of the connection between
two program methods
• Tight coupling
– Occurs when methods excessively depend on each other
– Makes programs more prone to errors
– Methods have access to the same globally defined
variables
• Loose coupling
– Occurs when methods do not depend on others
– Data is passed from one method to another
Understanding Recursion
42Programming Logic and Design, Eighth Edition
• Recursion
– Occurs when a method is defined in terms of itself
• Recursive method
– Calls itself
• Every time you call a method
– The address to which the program should return is stored
in a memory location called the stack
– When a method ends
• Address is retrieved from the stack
• Program returns to the location from which the method call was
made
Understanding Recursion (continued)
43Programming Logic and Design, Eighth Edition
Figure 9-20 A program
that calls a recursive
method
Figure 9-21 Output of program in Figure 9-20
Understanding Recursion (continued)
44Programming Logic and Design, Eighth Edition
• The stack holds the address where the program
should return at the completion of the method
– Has a finite size
– Will overflow if there are too many recursive calls
• Must provide a way for the recursion to stop
eventually
Understanding Recursion (continued)
45Programming Logic and Design, Eighth Edition
Figure 9-22 Program that uses a recursive
cumulativeSum() method
Figure 9-23 Output of program in
Figure 9-22
Understanding Recursion (continued)
46Programming Logic and Design, Eighth Edition
Figure 9-24 Nonrecursive program that computes cumulative sums
Summary
47Programming Logic and Design, Eighth Edition
• A method is a program module that contains a
series of statements that carry out a task
– Must include a header body and return statement
– A program can contain an unlimited number of methods
– Methods can be called an unlimited number of times
• Data passed to a method is called an argument
• Data received by a method is called a parameter
• Returned values must have a return type
Summary (continued)
48Programming Logic and Design, Eighth Edition
• Single array elements or entire arrays can be passed
• Overloading allows you to create methods with
different parameter lists under one name
• All modern languages contain prewritten methods
• Implementation is hidden in well-written methods
• Recursion occurs when methods call themselves;
logic becomes difficult to follow and hard to debug

More Related Content

Viewers also liked

Course Catalog
Course CatalogCourse Catalog
Course CatalogDan D'Urso
 
Fiebre por Madeline MartĂ­nez
Fiebre por Madeline MartĂ­nezFiebre por Madeline MartĂ­nez
Fiebre por Madeline MartĂ­nezmadelinemartinez
 
Equipo 1 tics windows 7
Equipo 1  tics windows 7Equipo 1  tics windows 7
Equipo 1 tics windows 7Itzelmedrano
 
Advanced Digital Menu Boards
Advanced Digital Menu Boards Advanced Digital Menu Boards
Advanced Digital Menu Boards charlesgehman
 
Tipos de redes
Tipos de redesTipos de redes
Tipos de redesMauricio Diaz
 
Internet social informĂ tica
Internet social informĂ ticaInternet social informĂ tica
Internet social informĂ ticaManel Vila
 
CAAS GREEN CHEMISTRY FINAL
CAAS GREEN CHEMISTRY FINALCAAS GREEN CHEMISTRY FINAL
CAAS GREEN CHEMISTRY FINALHans Plugge
 
A tecnologia sempre fez parte da sociedade
A tecnologia sempre fez parte da sociedadeA tecnologia sempre fez parte da sociedade
A tecnologia sempre fez parte da sociedadeAntonio Jackson Santana
 
Presentacion presupuesto
Presentacion presupuestoPresentacion presupuesto
Presentacion presupuestoCONPAD.CONSULTORES
 
Perspectivas para un plan global de accion contra el Mal de Panamá
Perspectivas para un plan global de accion contra el Mal de PanamáPerspectivas para un plan global de accion contra el Mal de Panamá
Perspectivas para un plan global de accion contra el Mal de PanamáExternalEvents
 
Fiche candidat concours siat final
Fiche candidat concours siat finalFiche candidat concours siat final
Fiche candidat concours siat finalmarouen chikhaoui
 
Scala gioco lombardino
Scala gioco lombardinoScala gioco lombardino
Scala gioco lombardinoimartini
 
How To Make Better Hiring Decisions For Your Business
How To Make Better Hiring Decisions For Your BusinessHow To Make Better Hiring Decisions For Your Business
How To Make Better Hiring Decisions For Your Businessaquigg
 

Viewers also liked (20)

Course Catalog
Course CatalogCourse Catalog
Course Catalog
 
A Tour To SQL
A Tour To SQLA Tour To SQL
A Tour To SQL
 
Fiebre por Madeline MartĂ­nez
Fiebre por Madeline MartĂ­nezFiebre por Madeline MartĂ­nez
Fiebre por Madeline MartĂ­nez
 
Feri
FeriFeri
Feri
 
Equipo 1 tics windows 7
Equipo 1  tics windows 7Equipo 1  tics windows 7
Equipo 1 tics windows 7
 
Advanced Digital Menu Boards
Advanced Digital Menu Boards Advanced Digital Menu Boards
Advanced Digital Menu Boards
 
Tipos de redes
Tipos de redesTipos de redes
Tipos de redes
 
Internet social informĂ tica
Internet social informĂ ticaInternet social informĂ tica
Internet social informĂ tica
 
CAAS GREEN CHEMISTRY FINAL
CAAS GREEN CHEMISTRY FINALCAAS GREEN CHEMISTRY FINAL
CAAS GREEN CHEMISTRY FINAL
 
Jenny rodriguez
Jenny rodriguezJenny rodriguez
Jenny rodriguez
 
A tecnologia sempre fez parte da sociedade
A tecnologia sempre fez parte da sociedadeA tecnologia sempre fez parte da sociedade
A tecnologia sempre fez parte da sociedade
 
Presentacion presupuesto
Presentacion presupuestoPresentacion presupuesto
Presentacion presupuesto
 
Perspectivas para un plan global de accion contra el Mal de Panamá
Perspectivas para un plan global de accion contra el Mal de PanamáPerspectivas para un plan global de accion contra el Mal de Panamá
Perspectivas para un plan global de accion contra el Mal de Panamá
 
Fiche candidat concours siat final
Fiche candidat concours siat finalFiche candidat concours siat final
Fiche candidat concours siat final
 
TEF
TEFTEF
TEF
 
Scala gioco lombardino
Scala gioco lombardinoScala gioco lombardino
Scala gioco lombardino
 
Chapter08
Chapter08Chapter08
Chapter08
 
Chapter10
Chapter10Chapter10
Chapter10
 
Motricidad
MotricidadMotricidad
Motricidad
 
How To Make Better Hiring Decisions For Your Business
How To Make Better Hiring Decisions For Your BusinessHow To Make Better Hiring Decisions For Your Business
How To Make Better Hiring Decisions For Your Business
 

Similar to CIS110 Computer Programming Design Chapter (9)

Csc153 chapter 07
Csc153 chapter 07Csc153 chapter 07
Csc153 chapter 07PCC
 
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
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfmadihamaqbool6
 
Csc153 chapter 08
Csc153 chapter 08Csc153 chapter 08
Csc153 chapter 08PCC
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfBernardVelasco1
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4ArnoldNarte
 
CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)Dr. Ahmed Al Zaidy
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06Terry Yoast
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12Terry Yoast
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2deathful
 
Java method present by showrov ahamed
Java method present by showrov ahamedJava method present by showrov ahamed
Java method present by showrov ahamedMd Showrov Ahmed
 
14method in c#
14method in c#14method in c#
14method in c#Sireesh K
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processMLG College of Learning, Inc
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
Using formal methods in Industrial Software Development
Using formal methods in Industrial Software DevelopmentUsing formal methods in Industrial Software Development
Using formal methods in Industrial Software DevelopmentRobert van Lieshout
 
Object oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleObject oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleVaibhav Khanna
 
test.pptx
test.pptxtest.pptx
test.pptxStacia7
 

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

Csc153 chapter 07
Csc153 chapter 07Csc153 chapter 07
Csc153 chapter 07
 
CIS110 Computer Programming Design Chapter (2)
CIS110 Computer Programming Design Chapter  (2)CIS110 Computer Programming Design Chapter  (2)
CIS110 Computer Programming Design Chapter (2)
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
Csc153 chapter 08
Csc153 chapter 08Csc153 chapter 08
Csc153 chapter 08
 
chapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdfchapter1-161229182113 (1).pdf
chapter1-161229182113 (1).pdf
 
Cs111 ch01 v4
Cs111 ch01 v4Cs111 ch01 v4
Cs111 ch01 v4
 
09. Methods
09. Methods09. Methods
09. Methods
 
I07 Simulation
I07 SimulationI07 Simulation
I07 Simulation
 
I07 Simulation
I07 SimulationI07 Simulation
I07 Simulation
 
CIS110 Computer Programming Design Chapter (1)
CIS110 Computer Programming Design Chapter  (1)CIS110 Computer Programming Design Chapter  (1)
CIS110 Computer Programming Design Chapter (1)
 
Functions ppt ch06
Functions ppt ch06Functions ppt ch06
Functions ppt ch06
 
9781285852744 ppt ch12
9781285852744 ppt ch129781285852744 ppt ch12
9781285852744 ppt ch12
 
Logic Formulation 2
Logic Formulation 2Logic Formulation 2
Logic Formulation 2
 
Java method present by showrov ahamed
Java method present by showrov ahamedJava method present by showrov ahamed
Java method present by showrov ahamed
 
14method in c#
14method in c#14method in c#
14method in c#
 
Lesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving processLesson 4.1 completing the problem solving process
Lesson 4.1 completing the problem solving process
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Using formal methods in Industrial Software Development
Using formal methods in Industrial Software DevelopmentUsing formal methods in Industrial Software Development
Using formal methods in Industrial Software Development
 
Object oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and exampleObject oriented programming 12 programming steps in cpp and example
Object oriented programming 12 programming steps in cpp and example
 
test.pptx
test.pptxtest.pptx
test.pptx
 

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 15 Risk Mitigation
Chapter 15 Risk MitigationChapter 15 Risk Mitigation
Chapter 15 Risk MitigationDr. 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

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

CIS110 Computer Programming Design Chapter (9)

  • 1. Programming Logic and Design Eighth Edition Chapter 9 Advanced Modularization Techniques
  • 2. Objectives In this chapter, you will learn about: • The parts of a method • Methods with no parameters • Methods that require parameters • Methods that return a value • Passing arrays to methods • Overloading methods • Using predefined methods • Method design issues, including implementation hiding, cohesion, and coupling • Recursion 2Programming Logic and Design, Eighth Edition
  • 3. The Parts of a Method 3Programming Logic and Design, Eighth Edition • Method – A program module that contains a series of statements that carry out a task – Invoke or call a method from another program or method – Any program can contain an unlimited number of methods – Each method can be called an unlimited number of times
  • 4. The Parts of a Method (continued) 4Programming Logic and Design, Eighth Edition • Method must include – Method header (also called the declaration or definition) – Method body • Contains the implementation (Statements that carry out the tasks) – Method return statement (Returns control to the calling method) • Variables and constants – Local: declared in a method – Global: known to all program modules
  • 5. 5Programming Logic and Design, Eighth Edition Figure 9-1 A program that calculates the user’s weight on the moon Using Methods with No Parameters Figure 9-2 Output of moon weight calculator program
  • 6. Using Methods with No Parameters (continued) 6Programming Logic and Design, Eighth Edition • When methods must share data – Pass the data into and return the data out of methods • When you call a method from a program, you must know three things: – Name of the called method – Type of information to send to the method, if any – Type of return data to expect from the method, if any
  • 7. Creating Methods that Require Parameters 7Programming Logic and Design, Eighth Edition • Argument to the method – Pass a data item into a method from a calling program • Parameter to the method – Method receives the data item • To write the declaration for a method that can receive a parameter, you must know: – The type of the parameter – The local name for the parameter
  • 8. Creating Methods that Require Parameters (continued) 8Programming Logic and Design, Eighth Edition • Parameter list – Types and names of parameters • Signature – Method’s name and parameter list
  • 9. Creating Methods that Require Parameters (continued) 9Programming Logic and Design, Eighth Edition • Improve the moon weight program by making the final output more user-friendly • Several approaches – Rewrite the program without including any methods – Retain the displayInstructions() method, but make the langCode variable global – Retain the displayInstructions() method as is, but add a section to the main program that also asks the user for a preferred language – Store the variable that holds the language code in the main program
  • 10. Creating Methods that Require Parameters (continued) 10Programming Logic and Design, Eighth Edition • Passed by value – A copy of a value is sent to the method and stored in a new memory location accessible to the method • Each time a method executes, parameter variables listed in the method header are redeclared
  • 11. Creating Methods that Require Multiple Parameters 11Programming Logic and Design, Eighth Edition • Methods can require more than one parameter – List the arguments within the method call, separated by commas – List a data type and local identifier for each parameter within the method header’s parentheses – Separate each declaration with a comma – The data type must be repeated with each parameter – Arguments sent are called actual parameters – Variables that accept the parameters in the method are called formal parameters
  • 12. 12Programming Logic and Design, Eighth Edition Figure 9-7 A program that calls a computeTax() method that requires two parameters Creating Methods that Require Multiple Parameters (continued)
  • 13. Creating Methods that Return a Value 13Programming Logic and Design, Eighth Edition • A variable declared within a method ceases to exist when the method ends – Goes out of scope • To retain a value that exists when a method ends, return the value from the method back to the calling method • When a method returns a value, the method must have a return type that matches the data type of the value that is returned
  • 14. Creating Methods that Return a Value (continued) 14Programming Logic and Design, Eighth Edition • Return type for a method – Indicates the data type of the value that the method will send back – Can be any type – Also called method’s type – Listed in front of the method name when the method is defined • Method can also return nothing – Return type void – Void method
  • 15. Creating Methods that Return a Value (continued) 15Programming Logic and Design, Eighth Edition • Example: num getHoursWorked() – Returns a numeric value • Usually, you want to use the returned value in the calling method – Not required – Store in variable or use directly without storing • output "Hours worked is ", getHoursWorked()
  • 16. 16Programming Logic and Design, Eighth Edition Figure 9-8 A payroll program that calls a method that returns a value Figure 9-9 A program that uses a method’s returned value without storing it Creating Methods that Return a Value (continued)
  • 17. 17Programming Logic and Design, Eighth Edition Creating Methods that Return a Value (continued) • Technically, you are allowed to include multiple return statements in a method – It’s not recommended – Violates structured logic
  • 18. 18Programming Logic and Design, Eighth Edition Creating Methods that Return a Value (continued) Figure 9-10 Unstructured approach to returning one of several values
  • 19. 19Programming Logic and Design, Eighth Edition Figure 9-11 Recommended, structured approach to returning one of several values Creating Methods that Return a Value (continued)
  • 20. 20Programming Logic and Design, Eighth Edition Creating Methods that Return a Value (continued) • To use a method, you should know: – What the method does in general, but not necessarily how it carries out tasks internally – The method’s name – The method’s required parameters, if any – The method’s return type, so that you can use any returned value appropriately
  • 21. 21Programming Logic and Design, Eighth Edition • IPO chart – A tool that identifies and categorizes each item in a method by input, processing, and output • A method that finds the smallest of three numeric values Figure 9-12 IPO chart for the method that finds the smallest of three numeric values Using an IPO Chart
  • 22. 22Programming Logic and Design, Eighth Edition • Many programmers create an IPO chart only for specific methods in their programs • Provide an overview of: – Input to the method – Processing steps that must occur – Result Using an IPO Chart (continued)
  • 23. 23Programming Logic and Design, Eighth Edition • Pass a single array element to a method – Same manner you would pass a variable or constant • Pass an entire array as an argument • Indicate that a method parameter must be an array – Place square brackets after the data type in the method’s parameter list • Passed by reference – Changes you make to array elements within the method are permanent Passing an Array to a Method Figure 9-45 Output of the PassArrayElement program
  • 24. 24Programming Logic and Design, Eighth Edition Figure 9-15 PassEntireArray program Passing an Array to a Method (continued)
  • 25. 25Programming Logic and Design, Eighth Edition Figure 9-15 PassEntireArray program (continued) Passing an Array to a Method (continued)
  • 26. 26Programming Logic and Design, Eighth Edition Figure 9-15 PassEntireArray program (continued) Figure 9-16 Output of the PassEntireArray program Passing an Array to a Method (continued)
  • 27. Overloading Methods 27Programming Logic and Design, Eighth Edition • Overloading – Involves supplying diverse meanings for a single identifier – Similar to English language—the word break can be overloaded to mean: • Break a window • Break bread • Break the bank • Take a break • Overload a method – Write multiple methods with a shared name but different parameter lists
  • 28. 28Programming Logic and Design, Eighth Edition • Call an overloaded method – Language translator understands which version of the method to use based on the arguments used • Polymorphism – Ability of a method to act appropriately according to the context – Literally, polymorphism means “many forms” Overloading Methods (continued)
  • 29. 29Programming Logic and Design, Eighth Edition Figure 9-17 Two overloaded versions of the printBill() method Overloading Methods (continued)
  • 30. 30Programming Logic and Design, Eighth Edition Figure 9-18 Two additional overloaded versions of the printBill() method Overloading Methods (continued)
  • 31. 31Programming Logic and Design, Eighth Edition • Overloading methods is never required in a program – Could create multiple methods with unique identifiers • Advantage is provided to your method’s clients – Those who use your methods need to remember just one appropriate name for all related tasks Overloading Methods (continued)
  • 32. 32Programming Logic and Design, Eighth Edition • Ambiguous methods – Situations in which the compiler cannot determine which method to use • Every time you call a method – Compiler decides whether a suitable method exists – If so, the method executes – If not, you receive an error message Avoiding Ambiguous Methods
  • 33. 33Programming Logic and Design, Eighth Edition Figure 9-19 Program that contains ambiguous method call Avoiding Ambiguous Methods (continued)
  • 34. Avoiding Ambiguous Methods (continued) 34Programming Logic and Design, Eighth Edition • Overload method correctly – Different parameter lists for methods with the same name • Ambiguous, not overloaded – Methods with identical names that have identical parameter lists but different return types – Example string aMethod(num x) num aMethod(num y)
  • 35. Using Predefined Methods 35Programming Logic and Design, Eighth Edition • Modern programming languages contain many methods that have already been written • Sources – Built-in methods – Program team members – Company-wide methods and standards • Save time and effort • Output methods • Mathematical methods
  • 36. Using Predefined Methods (continued) 36Programming Logic and Design, Eighth Edition • To use predefined methods, you should know: – What the method does in general – Name – Required parameters – Return type • You do not need to know: – How method is implemented
  • 37. Method Design Issues: Implementation Hiding, Cohesion, and Coupling 37Programming Logic and Design, Eighth Edition • Consider several program qualities – Employ implementation hiding • Clients don’ t need to understand internal mechanisms – Strive to increase cohesion – Strive to reduce coupling
  • 38. Understanding Implementation Hiding 38Programming Logic and Design, Eighth Edition • Implementation hiding – Encapsulation of method details • When a program makes a request to a method, it does not know the details of how the method is executed • A method that calls another must know: – The name of the called method – The type of information to send to the method – The type of return data to expect from the method
  • 39. 39Programming Logic and Design, Eighth Edition • Interface to the method – The only part of a method with which the method’s client interacts • Substitute a new method implementation – As long as the interface does not change, you do not need to make changes in any methods that call the altered method • A hidden implementation is often called a black box – You can examine what goes in and out but not how it works Understanding Implementation Hiding (continued)
  • 40. Increasing Cohesion 40Programming Logic and Design, Eighth Edition • It is difficult to decide how much to put into a method • Cohesion – How the internal statements of a method serve to accomplish the method’s purpose • Highly cohesive methods – All the operations are related – Functionally cohesive – Usually more reliable than those that have low cohesion
  • 41. Reducing Coupling 41Programming Logic and Design, Eighth Edition • Coupling – A measure of the strength of the connection between two program methods • Tight coupling – Occurs when methods excessively depend on each other – Makes programs more prone to errors – Methods have access to the same globally defined variables • Loose coupling – Occurs when methods do not depend on others – Data is passed from one method to another
  • 42. Understanding Recursion 42Programming Logic and Design, Eighth Edition • Recursion – Occurs when a method is defined in terms of itself • Recursive method – Calls itself • Every time you call a method – The address to which the program should return is stored in a memory location called the stack – When a method ends • Address is retrieved from the stack • Program returns to the location from which the method call was made
  • 43. Understanding Recursion (continued) 43Programming Logic and Design, Eighth Edition Figure 9-20 A program that calls a recursive method Figure 9-21 Output of program in Figure 9-20
  • 44. Understanding Recursion (continued) 44Programming Logic and Design, Eighth Edition • The stack holds the address where the program should return at the completion of the method – Has a finite size – Will overflow if there are too many recursive calls • Must provide a way for the recursion to stop eventually
  • 45. Understanding Recursion (continued) 45Programming Logic and Design, Eighth Edition Figure 9-22 Program that uses a recursive cumulativeSum() method Figure 9-23 Output of program in Figure 9-22
  • 46. Understanding Recursion (continued) 46Programming Logic and Design, Eighth Edition Figure 9-24 Nonrecursive program that computes cumulative sums
  • 47. Summary 47Programming Logic and Design, Eighth Edition • A method is a program module that contains a series of statements that carry out a task – Must include a header body and return statement – A program can contain an unlimited number of methods – Methods can be called an unlimited number of times • Data passed to a method is called an argument • Data received by a method is called a parameter • Returned values must have a return type
  • 48. Summary (continued) 48Programming Logic and Design, Eighth Edition • Single array elements or entire arrays can be passed • Overloading allows you to create methods with different parameter lists under one name • All modern languages contain prewritten methods • Implementation is hidden in well-written methods • Recursion occurs when methods call themselves; logic becomes difficult to follow and hard to debug