22
Introduction to Object- Oriented Programming Richard Fox (Diamond Valley College) VCAA Specialist Teacher - Digital Coding

Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Introduction to Object-

Oriented Programming

Richard Fox (Diamond Valley College)

VCAA Specialist Teacher - Digital Coding

Page 2: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Digital Technologies

Digital Systems

Data and Information

Creating Digital

Solutions

Page 3: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Curriculum is a continuum Creating Digital Solutions

Content Descriptions

Levels 3 and 4 Develop simple solutions as visual programs

Levels 5 and 6 Develop digital solutions as simple visual

programs

Levels 7 and 8

Develop and modify programs with user

interfaces involving branching, iteration and

functions using a general-purpose

programming language

Levels 9 and 10

Develop modular programs, applying selected

algorithms and data structures including

using an object-oriented programming

language

Page 4: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Prerequisites

• Algorithms, both as flowcharts and structured

English

• General purpose programming language (e.g.

C, Python, JavaScript)

Page 5: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Key concepts

Page 6: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

A collection of objects

Page 7: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

A collection of objects

Title: Emma

Author: Jane Austen

Title: David Copperfield

Author: Charles Dickens

Title: War and Peace

Author: Leo Tolstoy

Page 8: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

A class is a template

Title: War and Peace

Author: Leo Tolstoy

class Book

{

title: War and Peace

author: Leo Tolstoy

}

Page 9: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Another example Using classes is very convenient when we have

collections of objects, that share the same kind of

properties.

An example might be an Employee database. This is a

collection of records about individuals, but each

individual has the same kinds of data recorded for

them.

Page 10: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Properties

class Employee

{

firstName

lastName

dateOfBirth

salary

}

Fred Smith 23/02/1982 64,000

Page 11: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Methods A class can also contain methods.

These are functions that act on data

stored in the object’s properties. We

can think of them as commands that

the object understands.

Page 12: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Methods What are some methods that the Employee

class might require?

• Creating a new Employee

• Setting and getting the first name

• Setting and getting the last name

• Setting and getting the date of birth

• Setting and getting their salary

Page 13: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Methods class Employee {

// properties here

// methods

getFirstName() {

return firstName

}

setFirstName(newFirstName) {

firstName = newFirstName

}

}

Page 14: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Instantiation Whilst the class is the template for each object of that class, each

object in our program is an individual instance based on that

class.

We create a new object based on the class.

fred = new Employee(Fred, Smith, 23/02/1982, 64000)

fred is now an instance of the Employee class

Page 15: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Instantiation fred = new Employee(Fred, Smith, 23/02/1982, 64000)

Fred Smith 23/02/1982 64,000

Page 16: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Instantiation

Each new instance of a class is a new object,

and can store data related to that instance.

fred = new Employee(Fred, Smith, 23/02/1982, 64000)

mary = new Employee(Mary, Jones, 05/04/1968, 70000)

Page 17: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Instantiation fred = new Employee(Fred,Smith,23/02/1982,64000)

mary = new Employee(Mary,Jones,05/04/1968,70000)

Fred Smith 23/02/1982 64000

Mary Jones 05/04/1968 70000

Page 18: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Accessing data In many languages properties are accessed via dot notation, in the form of object.property

Fred Smith 23/02/1982 64000

print(fred.firstName) >> Fred print(fred.salary) >> 64000 print(mary.salary) >> 70000

Page 19: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Accessing data We may define some additional methods to work

with the data.

For example, if we want to print their full name …

fullName {

return firstName + “ “ + lastName

}

print(mary.fullName())

>> Mary Jones

Page 20: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Other features of OOP

• Inheritance – classes can have

subclasses

• Encapsulation – hiding the

implementation of a class from other

program code

Page 21: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Choosing a language

Most modern languages support OOP,

it is simply an extension to an existing

language.

Popular choices include Python,

JavaScript, C++, VB.NET.

Page 22: Introduction to Object-Oriented Programming...Most modern languages support OOP, it is simply an extension to an existing language. Popular choices include Python, JavaScript, C++,

Where next?

• Any recent textbook on the language

of choice

• Look for online courses and tutorials