- Learning to Program—The stages of programming
- Learning to Program – Some Terms You Should Understand
- Learning to Program – IPO Charts (Stage 1)
- Learn to Program- Flowcharting (Stage 2)
- Learning to Program – Flowcharting (Stage 2). — Decisions and Loops
- Learning to Program—Flowcharting (Stage 2) – Case Statements
- Learning to Program (Stage 2)—Flowcharting – Methods and Classes
- Learning to Program – Structure and Spaghetti Code
- Learning to Program – Pseudocode (Stage 3) an overview
- Learning to Program – Stage 3 Pseudocode commands and reserved words
- Learning to Program—Stage 3 Pseudocode examples Part 1
- Learning to Program – Stage 3 Psuedocode (Arrays)
- Learning to Program – Stage 3: Pseudocode—Methods
- Learning To Program—Stage 3.5 (UML Diagrams)
- Learning to Program – (Stage 4) Coding
- Learning To Program—Stage 5 Testing
- Learning to Program—Stage 6 (Documentation)
- Learning to Program – Stage 7 (Maintenance)
- Learning to Program—Random Thoughts with a Theme
- Learning to Program- Two Main Types of Errors
- Learning to Program – Integrated Development Environments (IDE’s)
- Learning to Program
In previous posts, I described the symbols used in flowcharting and an idea of the flow in a program. I also discussed the different decisions and loops that you may encounter in a program. I pointed out that while you may use a name for the loop or decision, you do not put that name in the flowchart. This is because the flowchart is only meant to be a graphical representation of how the program will flow through (not the actual code it will use to make that flow).
In this post, I will discuss the flow of using methods and classes. However, a little explanation of where you will use methods and classes is in order.
A method is used whenever you have some code that you will use in different places throughout your program. An example of this would be if you print output that follows a certain format (a string, then a number, then a number for example). As long as the variables passed into the method are the same type as the variables receiving in the method, they don’t have to be the same (or contain the same information).
A class is a special type of method. In general, a class is a method that is able to be used by more than one program. For example, if you have an accounting program, and a program that handles cash register duties, they both may need to use a method which calculates sales tax. Instead of writing this method twice, you would create a class and call it in both programs as needed.
The beauty of methods and classes (when it comes to flowcharts) is this. They are both called in the exact same way. The main difference is in the pseudocode or code, when you declare that you’ll use a class (you don’t declare methods which are a part of the same program). Classes are stored as a separate file.
There are four scenarios for calling a method: calling a method without arguments and without returning a value, calling a method without arguments and returning a value, calling a method with arguments and not returning a value, and calling a method with arguments and returning a value. I will show you the flowcharts for each of these in order.
Calling a method without arguments and not returning a value.
Calling a method with arguments and not returning a value.
Calling a method without arguments and returning a value.
Calling a method with arguments and returning a value.
In older programming languages (COBOL or Pascal for exmaple), you would see the calling without arguments and returning a value in read statements. However it’s rare to do this now. The most common methods that you will see are calling with arguments and not returning a value, and calling with arguments and returning a value.
There are other aspects of flowcharting that you will run into. However most of them can be broken down into the different types that I showed you here already. It’s more a matter of breaking the requirement down into the individual steps to achieve it and flowcharting it out.
So, with this, we shall move onto pseudocode.
Have a great day:)