Objects Methods and Instantiation. Programming Programming is the act of writing instructions that...

24
Objects Methods and Instantiation

Transcript of Objects Methods and Instantiation. Programming Programming is the act of writing instructions that...

Page 1: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Objects Methods and Instantiation

Page 2: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

ProgrammingProgramming is the act of writing instructions that tell a

computer how to do something.

This module is a starting point into a huge topicYou will almost certainly not get this on the first attemptI assume no prior knowledge of programming

In this first lecture we will consider…How we may use a system of notation to control computer

technologyHow objects may be used to represent and control

computer technology via methods and propertiesThe relationship between an object and a class and how

instantiation creates an object from a class

Page 3: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Sending a Simple Instruction to a Computer

I want the computer to shut down

How would I do this?(Use of my senses)

How would I tell one of you to do it?(Use of natural language)

How do we tell the computer to turn itself off?

Page 4: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Natural Language and Computers“ok computer turn your self off now”

Does the computer understand the words we have used?

Strong regional accents?

Consider the following…Off computer turn nowOK puter turn thesel ov nowCmptr trn yrslf ff nw

Natural language allows for ambiguity and imprecision

Computers are really quite thick

Page 5: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Computer Programming and MusicParallels may be drawn between

programming a computer and playing an instrument.

(It is my observation that many programmers are also musicians)

With music we have the same problem as with a computer

How do we tell the instrument / musician what it is we want to hear?

Page 6: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

What is this?

Page 7: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Add the words…

Page 8: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Music Notation as a ProgramOnce you understand the rules you may create /

play music of varying complexityThe same tune may be reproduced on different

instrumentsThe basic rules are very simpleThe staff indicates the pitch of the sound…

The shape of the notes tell us how long they should be played for…

Sequence matters!

Page 9: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Symbols and MeaningWe use symbols all of the time in our daily life

“Represents” the tune “three blind mice” but it isn’t the tune

De Montfort UniversityThe GatewayLeicesterLE1 9BH

Represents the address but it isn’t the place

Page 10: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Understanding the Symbols

Understanding the symbols is the first problem you will face in learning how to program

Page 11: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Which Code is Correct? Dim MyAge As Integer MyAge = 23 If MyAge > 21 Then lblError-Text = "You are old enough" End If

Or…

Dim MyAge As Integer MyAge = 23 If MyAge > 21 Then lblError.Text = "You are old enough" End If

Page 12: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Computer ProgrammingWe want to create:

A system that accurately identifies the individual components in a computer so we may control them

A system that may be used to set the sequence of instructions such that they are carried out in the way we intend

A system of representation that is easy to maintain avoiding unnecessary duplication and excess baggage

Something that is reasonably easy for us as human beings to write and understand (we don’t want the symbols to get in the way of the meaning)

Page 13: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Objects, Classes, Methods, Properties and InstantiationLots of new terms to understand

Objects provide tools for referencing and controlling bits of the computer

Classes are the “recipes” that define objectsMethods tell objects to do somethingProperties control the settings of an objectInstantiation is the act of making an object out

of a class

Page 14: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Cuba the Cat - PropertiesLegs 4Tails 1Ears 2Fangs 3

Properties tell us how the object is set up

Page 15: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Cuba the Cat - MethodsRelease - let

Cuba outsideFeed - give

Cuba some food

Scoop - clean up after Cuba

Methods make the object do something

Page 16: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

The Computer as an ObjectProperties and methods not about CatsWe want to represent and control the computerView the computer system as a set of objectsWe may think of the computer expressed as an

object

MyComputer.TurnOff()

MyComputer represents the entire computerTurnOff is a method that turns the computer offStarting to develop a system of notation rather like

musical notation

Page 17: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

ClassesClasses contain the code defining an object

Page 18: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

InstantiationTakes the recipe contained in the class and

makes an object we may use

Page 19: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

The Computer SystemWe will be looking at a range of objects and

classes allowing us to control different parts of the computer systemThe screen (buttons, text boxes and lists)The RAM (variables)A Database (DataConnection class)+ othersAlso look at control structures (assignment,

functions, loops, if statements)

Page 20: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

The Three Layer Architecture

Page 21: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

OverviewDon’t get bogged down in the detail!

Programming is the act of writing instructions that tell a computer how to do something

We need a standard system of notation allowing us to represent what the computer is to do that makes

reasonable sense to human beings

Page 22: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Important Key ConceptsObject A way of representing computer

technology so that we may control it

Method Used to tell an object to do something

Property Used to find out or control something out about the object

Class The definition for an objectInstantiation The process of making an

object from a class

Page 23: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Computer System Split into LayersThe Presentation Layer – the part the user

interacts with

The Middle Layer – containing classes allowing us to do things

The Data Layer – where are database is stored

Page 24: Objects Methods and Instantiation. Programming Programming is the act of writing instructions that tell a computer how to do something. This module is.

Finally…There is one final way in which programming is like

music! 

Both require constant hands-on practise! You must do the work! You will not learn how to program on the first second

or third attempt You must practise and refine your skills