Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another.

Similar presentations


Presentation on theme: "Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another."— Presentation transcript:

1 Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another section is done Repetition: Do a section repeatedly, either a fixed number of times, or until a condition occurs Parallel Execution: Do the lines at the same time

2 Subprograms Often a section of a program is done repeatedly, but in different parts of the program. Such a section can be made a subprogram, which is written once, but called many times. Even when a section of code is called just once, it may be useful to make it a subprogram, because conceptually, it is one whole thing. This is useful in larger programs.

3 Advantages of Subprograms Coding, debugging, and modifying a subprogram is easier, because there's only one copy of the code and it's all in the same place. It's easier for humans to understand programs that are broken down into well-designed pieces. The code may be have values that change from call to call, and thus may operate using different values. Code can be written by different people.

4 Objects In Object-Oriented design, the programming task is broken down in to various objects. Each object has its own set of properties, e.g., color, position, height, and methods, e.g., moveTo, faceTowards, which can be thought of as actions. Objects can interact with one another.

5 Classes A class is a blueprint for a set of objects. The class specifies what the properties are for the object and what the methods (actions) are. The actual value of the properties for a particular object differ from object to object, but all objects of the same class have the same set of properties and methods.

6 Instance An object of a particular class is called an instance of that class. For example, the Dragon class may specify all the methods of properties that Dragons may have, while bobTheDragon may be a particular Dragon with a particular set of values for its properties. maryTheDragon could be a different Dragon, with a different set of properties. They would employ the same methods however.

7 Example The Dragon class may specify that Dragons have color, position, and size. JoeTheDragon might be green, be flying at position (10,10), and be of size 2, while bettyTheDragon might be red, standing at position (0,0), and be of size 5. All Dragons would share the same methods.

8 Parts Objects can be parts of other objects, e.g., a snowman may have arms, legs, and a head. The head may have a hat. Each sub-part may have its own properties and methods.

9 Functions Functions are special subprograms that return a value. Functions can be used to return property information about an object, do arithmetic calculations, or even tell how things are related. Examples: snowman1.size(), x.plus(3), snowman1.size().lessThan(5).

10 State At any point in time, a program is in a particular state. The state represents where all the objects are, and what the values of their properties are, as well, as perhaps some global information. As the program progresses, the information stored in the state changes.

11 Variables In many programming languages (without objects), values are stored just in variables. In object-oriented languages, the properties of objects can be though of variables which are attached to the object. Variables can be simple or compound. A simple variable contains one value. A compound variable can contain multiple values, but they must be organized in some fashion.

12 Variables (cont'd) You can think of a simple variable as a box, which can hold one thing, and only one thing. You can change the contents of the box, or retrieve the contents of the box. In many programming languages, a variable can only hold one specific kind of thing. For example, a hat box, can only contain hats, and a shoebox can only contain shoes.

13 Types The kind of things that a variable can hold is called a type. Examples of types are (in C++) are ints (which are whole number values, or integers), double (which represent real values), bool (for Boolean, which are values that are either true or false). C++ variables can also be used to hold strings (which are text). In Alice, four common types are: number, Boolean value, string, and object.

14 Identifiers Variables also have names, which are how humans know which variable is which. Names of variables are a type of identifier. Other things, such as subprograms, functions, methods, and objects also have names which are identifiers. Each programming language has rules about forming valid identifiers.


Download ppt "Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another."

Similar presentations


Ads by Google