Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT is gr8! A workshop for IT teachers 2015. Preparing for programming concepts Data types Arrays (lists) OOP Classes and objects Attributes and behaviour.

Similar presentations


Presentation on theme: "IT is gr8! A workshop for IT teachers 2015. Preparing for programming concepts Data types Arrays (lists) OOP Classes and objects Attributes and behaviour."— Presentation transcript:

1 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. 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 is treated as a string because it was entered as the argument of the length function.

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.

6 Programming concepts: Arrays

7

8

9 Programming concepts: OOP 1.Re-use of code (code stored in a unit) 2.Passing data to pre-written code 3.An object has attributes (data) and behaviour (methods) 4.Data encapsulation a)Data can only be passed to, and obtained from an object using methods. b)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 ‘Static’ components 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 1.Use the unit where the class has been declared. 2.Declare a variable based on the class. 3.Instantiate the object. 4.Call methods from the object. 5.Free the object.

15 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...

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. You can also use objects which are not visible at run-time of the program, for example a TStringList.

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

21 How to instantiate and use an object based on a TStringList class 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 Function Power(Base: Extended; Exponent: Extended): Extended; rAns := POWER(StrToInt(edtBase.Text), StrToInt(edtPower.Text)); Re-confirming concepts

24 Passing data to an object Re-confirming concepts

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 and Behaviour  Provide his/her name  Provide the number of hours worked  Provide the rate per hour  Calculate and provide total wage The TWaiter class definition will be stored in the clsWaiter_u unit. (You choose the name of the unit yourself.)

27 How to instantiate and use an object based on a TWaiter class Grade 12 Chapter 1 Activity 1.2

28

29 An object contains attributes and behaviour 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). Re-confirming concepts

30 Behaviour Attributes

31 frmMain frmHideCachefrmSwopfrmSearch Prepare for concepts

32 Use OOP principles Methods are part of the class of the Form. Methods work with attributes (data) of the Form.

33 Do NOT use procedural principles Subroutines work with a variable which has unit scope. Subroutines - not methods.


Download ppt "IT is gr8! A workshop for IT teachers 2015. Preparing for programming concepts Data types Arrays (lists) OOP Classes and objects Attributes and behaviour."

Similar presentations


Ads by Google