Teach A-Level Computer Science: Object-Oriented Programming in Python

Slides:



Advertisements
Similar presentations
Python Objects and Classes
Advertisements

CS104: Chapter 15 CS 104 Students and me. Big Question Q: You say creating a class is how to create a new type. Why would we even want to do this?! A:
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Chapter 4&5 Defining Classes Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
Road Map Introduction to object oriented programming. Classes
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
ASP.NET Programming with C# and SQL Server First Edition
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
UFCEUS-20-2 : Web Programming Lecture 5 : Object Oriented PHP (1)
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Centre for Computer Technology ICT115 Object Oriented Design and Programming Week 2 Intro to Classes Richard Salomon and Umesh Patel Centre for Information.
© 2008 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Classes 1 COMPSCI 105 S Principles of Computer Science.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
 Computer Science 1MD3 Introduction to Programming Michael Liut Ming Quan Fu Brandon.
Object Oriented Programing (OOP)
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Introduction to Object-Oriented Programming Lesson 2.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Exceptions and Handling
Object Oriented Programming Some Interesting Genes.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Object Oriented Programming
Classes and OOP.
Objects as a programming concept
The Object-Oriented Thought Process Chapter 1
Today’s Objectives Review the important points of classes
Chapter 3: Using Methods, Classes, and Objects
11.1 The Concept of Abstraction
Object Oriented Programming
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object-oriented programming
Procedural Abstraction Object-Oriented Code
Object-oriented programming
To Get Started Paper sheet
Abstract Data Types and Encapsulation Concepts
Object-oriented programming
Inheritance Basics Programming with Inheritance
Object-oriented Design in Processing
IFS410: Advanced Analysis and Design
Teach A-Level Computer Science: Object-Oriented Programming in Python
Computer Programming with JAVA
Object-oriented Design in Processing
An Introduction to Object Orientated Programming
CPS120: Introduction to Computer Science
Object-Oriented Programming
Object Oriented Programming in A Level
Object-oriented Design in Processing
Object-Oriented PHP (1)
CPS120: Introduction to Computer Science
2.1 Introduction to Object-Oriented Programming
A Level Computer Science Topic 6: Introducing OOP
Programming For Big Data
Lecture 1 Introduction to Software Construction
Object-oriented Design in Processing
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Teach A-Level Computer Science: Object-Oriented Programming in Python Session 1 Introduction Theory: Classes and Objects Practical: OOP programming basics in Python

Course Outline Week No Understanding computers (5:30– 6:30) Developing programming skills (7:00 -8:00) Week-1 Week 1 – Introduction to Classes and Objects Week 1 – OOP Programming basics Week-2 Week 2 – Encapsulation and introduction to python modules Week 2- Variables and objects, OOP Programming using python modules Week-3 Week 3 – Understanding Inheritance and composition Week 3 – Programming using Inheritance Composition vs Inheritance Week-4 Week 4 - Polymorphism Week 4 – Different kinds of Polymorphism Week-5 Week 5 - Consolidation

Session -1 Outline Introduction to Class and objects Python built-in objects Introduction to user defined class and object Understanding the use of self and __init__ method Multiple instances

What is OOP? Abstraction: Abstraction is the process of creating a general idea(model) of the problem by removing specific details that will not help to solve the problems. Object Oriented Programming is all about abstractions. OOP reduces the complexity of the problem by grouping the functions and variables together. Data hiding refers to hiding representation details from users. characteristics/variables/attributes behaviour/functions/methods OCR and Eduqas  methods and attributes , AQA  methods and property/attribute fields

Classes and Objects Class is the blueprint or template for creating definition of objects Classes will have a class name, attributes and methods Objects are instances of class and the process of creating objects from classes is called instantiation Let us look at an example of mobile phone class Task1: Discuss in pairs what could be attributes and methods of mobile phones class. Mobile Phones class Samsung Galaxy object2 Sony Xperia object 3 iPhone object1 Example answers: Attributes size, colour, model etc. Methods calling, locking , security

Example of Python built-in Objects Python lists A specific named list is an example of a built-in Python object. For example Colours list will be used to store different colours (attributes) as a single container and it also has methods that we use to manipulate items inside that list. Remember these methods cannot be used on any other attributes outside that list. Task2 : Worksheet (Page1) Colours List (Attributes) “Red” “Green” “Blue” “Orange” “Purple” “Black” “Yellow” append() sort() clear() copy() reverse() Methods

Python Conventions Capitalise your class names _ _  Double underscore for Python special methods. e.g. __init__ self parameter to reference an object at runtime An attribute with a leading underscore is reserved for use within that class.

User Defined Classes and Objects To define our own class we use the keyword class Example1: Let us create a definition for Staff object Step1: Create a class Staff Step2: Let us define a method greet () for this class Outside Class: Step3: Let us create an object from class Staff() (Instantiation) Now run the program and see what happens Python will use our class Staff() to create a new instance of staff. staff1 is the variable used to make a reference to the first instance of class Staff(). Now we can use staff1 to call all methods defined in class Staff()

Use of self .self is a reference to the object so let us modify the code by adding self to make it work So when we use staff1.greet() self inside the function will point to the same object. class Staff(): def greet(self):

Multiple Instances We would like to personalise the welcome message for different people We can create multiple objects from the same class Do you think this is an efficient method?

Python __init__ method . Every OOP language uses special methods called Constructors to construct and initialise an object with specific attributes Python does not include constructors but uses a special method __init__ for initialising an object and is invoked when you instantiate an object Python special methods wouldn’t allow you to interact directly but is invoked implicitly Python special methods always start with __(double underscore) Tasks 3, 4 and 5: Worksheet (Page1) Staff ‘Melissa’ greet() Staff ‘Dharini’ greet() Staff ‘Sue Sentence’ greet() Instantiation refers to the process of crating an instance of a class.

Let us continue after break