Presentation is loading. Please wait.

Presentation is loading. Please wait.

A workshop for IT teachers

Similar presentations


Presentation on theme: "A workshop for IT teachers"— Presentation transcript:

1 A workshop for IT teachers
IT is gr8! A workshop for IT teachers 2015

2 Preparing for programming concepts
Data types Arrays (lists) OOP Classes and objects Attributes and behaviour of objects Data transfer to and from an object

3 Programming concepts: Data types
All the operators work with numbers. All the slots are round. There is a difference between integer and real values. Drag one operator block to the script area in Scratch. Enter numbers. Click on the block. The result of the operation will appear in a pop-up. In this way calculations with different data types can be emphasized without having to write a complete program. Round is a function. It receives one argument. It returns an integer.

4 Programming concepts: Data types
All the operators work with text (strings). All the slots which can accept text are rectangular. The slot which contains a number (3) is round. 34251 is treated as a string because it was entered as the argument of the length function. Use programming terminology, e.g.: The join function has two parameters. In this example it receives the words Hi and Jenny as arguments. It returns a string.

5 Programming concepts: Data types
When you compare values you create a condition. The result of a condition is a Boolean value. Boolean values fit into slots with pointed sides. Explain to learners that programming languages do not treat strings in the same way. Scratch do not consider upper and lower case letters to be different. (It is not case sensitive.) Other languages (such as Delphi), use the ASCII value of a character to decide if one letter is ‘larger’ than another one.

6 Programming concepts: Arrays
Let learners write the same proram in Delphi and Scratch. In this way they see that it is only the syntax which is different.

7 The two blocks are actually event handlers
The two blocks are actually event handlers. The list (array) had to be declared with stage scope, because both event handlers need access to it.

8 In Delphi we draw a visual representation of an array (list of values)
In Delphi we draw a visual representation of an array (list of values). In Scratch the list can be displayed on the Stage.

9 Programming concepts: OOP
Re-use of code (code stored in a unit) Passing data to pre-written code An object has attributes (data) and behaviour (methods) Data encapsulation Data can only be passed to, and obtained from an object using methods. An object’s methods act on its own data.

10 Why OOP? Delphi is an OOP language. It has been developed using objects. You have already used objects. You are going to learn how to create your own objects.

11 Where have you used objects?
Buttons, Panels, Edits (all are components – a special type of object). These components have been created according to a ‘blueprint’ or ‘recipe’ called a class.

12 You have used static components, and instantiated components dynamically
Dynamic components (instantiated while program is running) MyPanel := TPanel.Create(frmPicture); MyLabel := TLabel.Create(MyPanel); MyImage := TImage.Create(MyPanel);

13 Classes The definitions (blueprint / recipe) for components are called classes and they are stored in units.

14 How to instantiate and use an object based on a class
Use the unit where the class has been declared. Declare a variable based on the class. Instantiate the object. Call methods from the object. Free the object. Guidelines to remember all the steps involved when an object is instantiated. In the beginning it helps learners if they write down the steps and refer to it while working.

15 Grade 11 Chapter 13 Activity 3.1
Create a visible object (component) based on a class supplied by Delphi. The name of the unit (ComCtrls) which contains the class definitions of components is added to the uses clause by Delphi. It is still step 1. Grade 11 Chapter 13 Activity 3.1

16 Delphi also provided other classes which can be used to instantiate objects. We want to create our own classes and instantiate objects based on these classes. So we need to know how an object is structured . . . The purpose of the lesson is to learn to create your own class. Therefore we need to know how an object is structured.

17 What does an object look like?
All objects have attributes (describing what the object looks like) and behaviour (indicating what the object can do). For example . . .

18 The various attributes and the behaviour have been indicated in a class definition (a recipe or blueprint) which is stored in a unit. For example the TEdit class definition is stored in the StdCtrls unit.

19 Components are visible objects
Components are visible objects. You can also use objects which are not visible at run-time of the program, for example a TStringList.

20 The TStringList class definition is stored in the Classes unit.
A StringList has Attributes Text (an array/list of strings) Count (an integer indicating the number of strings in the list) The TStringList class definition is stored in the Classes unit. and Behaviour AddStrings Delete Exchange Sort IndexOf SaveToFile LoadFromFile

21 How to instantiate and use an object based on a TStringList class
Create an invisible object based on a class supplied by Delphi. The name of the unit (Classes) which contains the class definitions of components is added to the uses clause by Delphi. It is still step 1. Grade 11 Chapter 13 Activity 5

22 Benefits of using the TStringList class
Learners can see the benefit of using classes. They experience the concept of data encapsulation. They want to create their own classes or collaborate and exchange classes.

23 Passing data to a subroutine
Re-confirming concepts Passing data to a subroutine Function Power(Base: Extended; Exponent: Extended): Extended; rAns := POWER(StrToInt(edtBase.Text), StrToInt(edtPower.Text)); Remind learners that they wrote programs before where they had to pass data to a separate entity (pre-written code). When using objects, they have to specify the name of the object before calling a method. E.g. MyTextData.Add(‘Hallo’); similar to redOut.Lines.Add(‘Hallo’);

24 Passing data to an object
Re-confirming concepts Passing data to an object

25 Write your own class and instantiate an object
When you write many programs, and more complicated ones, it may be necessary to create your own classes, so you can create the same objects in different programs, or so you can do more complicated programming in a separate entity. We are going to use an uncomplicated object to begin with: A waiter as an object.

26 A Waiter has Attributes Name Number of hours the waiter worked Rate the waiter earns per hour The TWaiter class definition will be stored in the clsWaiter_u unit. (You choose the name of the unit yourself.) and Now you create your own class, based on the structure of a class provided by Delphi. Behaviour Provide his/her name Provide the number of hours worked Provide the rate per hour Calculate and provide total wage

27 How to instantiate and use an object based on a TWaiter class
The same 5 steps. Since the class is not provide by Delphi, you have to include the name of the unit where the class is stored in the uses clause. Grade 12 Chapter 1 Activity 1.2

28

29 An object contains attributes and behaviour
Re-confirming concepts A Form is an object (component). While you are building a new Form, you are adding attributes (components and variables with class scope). You are adding behaviour (event handlers and methods – functions and procedures).

30 Attributes Behaviour While you were adding components and creating event handler and methods, Delphi entered the necessary statements in the Form’s class declaration.

31 frmMain frmHideCache frmSwop frmSearch Prepare for concepts
In Grade 11 learners use multiple forms. This is an example of a strategy followed in a learner’s Geo cache PAT. On the main Form the user had to log in using a username. On the other forms, the username is needed to perform certain operations. Even though learners do not know how to create classes, you can teach them this method to transfer the username to another form (an object). Write a ‘set’ method for the form which should receive the username (frmHideCache). This corresponds to the mutator methods they will learn about when they write their own classes. To the learners it is clear why the Set method is needed. Once they are in Grade 12, you can refer back to this technique when explaining the Set method for their own classes.

32 Use OOP principles Methods are part of the class of the Form.
Methods work with attributes (data) of the Form. Once learners write their own classes, show them how it corresponds to a Form’s class.

33 Do NOT use procedural principles
Subroutines - not methods. If variables are declared in the implementation section of the unit of the Form, the variable has unit scope, not class scope. The program will work, but it does not follow OOP principles. This may confuse learners, and will not contribute to their understanding of writing their own classes. Subroutines work with a variable which has unit scope.


Download ppt "A workshop for IT teachers"

Similar presentations


Ads by Google