Download presentation
Presentation is loading. Please wait.
Published byRidwan Sudirman Modified over 5 years ago
1
Functions, Return Values, Parameters Getters and Setters
2
Procedures in Everyday Life
We use procedures all time – fire drill or recipe They are set up in advance with a detailed set of instructions We only refer to them (Call them) when we need them Procedures allow us to repeat the same task over and over again
3
Function Procedures Procedures in programming languages are the same
They are set up in advance with a detailed set of instructions We only refer to them (Call them) when we need them Procedures allow us to repeat the same task over and over again
4
A Function by any other name
Often referred to by different names Function Function procedure Sub procedure Sub Stored procedure
5
Benefits of Functions Give greater functionality Hide complexity
Promote code re-use Simplify maintenance
6
Functions gives Greater Functionality
When we want to use the function we simply call it
7
Hides Complexity Who cares how it works?
8
Simplify Maintenance Create a function
Call it multiple times around our system Need to make a change Modify the one function definition All of the multiple calls benefit from the change
9
Functions Promote Code re-use
A function should perform one task well Accept enough data via parameters for the task Return an appropriate value Organise into class libraries Allow us to recycle code
10
Functions are used to make…
Event handlers Public methods in a class Public properties in a class Constructors Test cases None of the above just a function
11
Function Example
12
Return Values Two parts of the function work together…
13
Pick the Return Data Type
14
Calling Functions May use function with the assignment operator…
When a function call is completed the flow of code returns to the line where the call was made from!
15
Ignoring the Return Value
16
Void Functions
17
Parameters This code is not very versatile… Add parameters…
18
Use the Parameters
19
Calling the Function with Parameters
20
Public Functions to make Methods
Public function in a class file Becomes a method in an object
21
Public Functions to make Properties - Getters and Setters
22
Using the Debugger with Functions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.