Object-oriented programming

Slides:



Advertisements
Similar presentations
By Waqas Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most.
Advertisements

OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
Week 8 Recap CSE 115 Spring Composite Revisited Once we create a composite object, it can itself refer to composites. Once we create a composite.
Object–Orientated Design. OOP Design Describe the following: a computer a university Usually the most natural way to describe a task is to list the entities.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Object-oriented Programming Concepts
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
BACS 287 Basics of Object-Oriented Programming 1.
Object Oriented Software Development
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
Programming Pillars Introduction to Object- Oriented Programming.
Classes 1 COMPSCI 105 S Principles of Computer Science.
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Problem of the Day  What is the smallest positive integer that cannot be defined in less than twenty-five syllables?
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Chapter Object Oriented Programming (OOP) CSC1310 Fall 2009.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
CET203 SOFTWARE DEVELOPMENT Session 2A Inheritance (programming in C#)
Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CSC 108H: Introduction to Computer Programming Summer 2012 Marek Janicki.
CE-105 Spring 2007 By: Engr. Faisal ur Rehman
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Section 2.1: Programming paradigms
Object Oriented Programming
JAVA By Waqas.
Objects First with Java A Practical Introduction using BlueJ
Object-Oriented Programming Basics
Interface, Subclass, and Abstract Class Review
Objects as a programming concept
The Object-Oriented Thought Process Chapter 1
OOP What is problem? Solution? OOP
Week 4 Object-Oriented Programming (1): Inheritance
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Section 2.1: Programming paradigms
Object Oriented Programming in Python
Object Oriented Programming
Chapter 7 Classes & Objects.
3 Fundamentals of Object-Oriented Programming
Objects First with Java A Practical Introduction using BlueJ
Object-oriented programming
Chapter 10 Thinking in Objects
Object-oriented programming
Chapter 9 Object-Oriented Programming: Inheritance
MSIS 670 Object-Oriented Software Engineering
Teach A-Level Computer Science: Object-Oriented Programming in Python
Chapter 9 Classes & Objects.
Teach A-Level Computer Science: Object-Oriented Programming in Python
Programming paradigms
An Introduction to Object Orientated Programming
Java Programming, Second Edition
ITEC 3220A Using and Designing Database Systems
Objects First with Java A Practical Introduction using BlueJ
CPS120: Introduction to Computer Science
Object-Oriented Programming
Object Oriented Programming in A Level
Object Oriented Programming in A Level
Objects First with Java A Practical Introduction using BlueJ
Final and Abstract Classes
Programming For Big Data
Presentation transcript:

Object-oriented programming Session 3 Inheritance

Course Outline Week No Understanding Developing programming skills Week 1 – Introduction to Classes and Objects Week 1 – OOP Programming basics Week-2 Week 2 – Variables and objects, Python Modules Week 2- Creating and using Python modules Week-3 Week 3 – Inheritance Week 3 – Programming using Inheritance Week-4 Week 4 – Polymorphism and Overriding Week 4 – Programming using different kinds of Polymorphism Week-5 Week 5 - Consolidation

Session 3 Outline To understand the inheritance relationship Create and use inheritance Examples Used: Person Students Teacher HOD

Recap: Classes and Objects OOP attempts to simulate the real world by means of objects which have characteristics and functions A class is a combination of variables, called attributes, and procedures, called methods, forming a self-contained programming entity An object is one instance of the class definition. The class definition is the blueprint or template that we use Classes are accessed via their methods, not directly. This means that OOP classes can be reused in many different programs without us needing to know how they work.

Video Class example : video Properties (attributes) Title Year Certificate Genre VideoID HirePrice Methods (procedures) GetVideoDetails UpdateHirePrice SetGenre Video

Car Object example : car Methods (procedures) GetCarDetails Properties Make Model Mpg Engine size Year of reg Mileage Car Reg Methods (procedures) GetCarDetails UpdateMileage CalculateAge Car

Python Standard practice Include the constructor __init__ () for all classes In every class all methods other than the constructor will return a value All input statements will be used outside the class and the values will be passed as parameters when instantiating.

Inheritance One class can inherit methods and variables from another class This is called inheritance For example, in a system for a school, there may be a Student class and a Staff class (enabling you to create Student and Staff objects) There also may be TeachingStaff, SupportStaff, ManagementStaff classes. These could inherit methods and variables from the Staff object. In this case Staff is the super class and TeachingStaff is the sub class (or child class)

Attributes as above PLUS department, gradelevel, contact hours Inheritance Attributes: name, address, email Staff SupportStaff TeachingStaff ManagementStaff Please complete diagram exercises Attributes as above PLUS department, gradelevel, contact hours

Inheritance Inheritance: In OOP inheritance is the process whereby a class inherits methods and attributes from a base/parent/superclass. A class which inherits from a superclass is called a subclass or child class. Inheriting class may override some of the methods and attributes and may also have extra methods/ attributes on its own. Composition : We can consider composition when we look at polymorphism (week 4)

Inheritance in Python Before writing classes in Python, ensure that you have written all the methods and attributes you will need on paper. An example: a Student is a type of Person so can inherit from the Person class Attributes and methods in red are inherited so don’t need to be repeated. Class Attributes Methods Person firstname, lastname, email Fullname Student Firstname, lastname, email, tutor group, year group Studentdetails

Person and Student class Q: write the code to create an actual person called Cristiano Ronaldo with the email address cronaldo@gmail.com A: person1 = Person(“Cristiano”, “Ronaldo”, cronaldo@gmail.com)

Person and Student Classes The sub-class Student is defined as follows: The Superclass is given in brackets – eg class Student(Person) The line of code super().__init__(firstname,lastname,email_address) is included in the constructor Please work on Activity1

More classes in this example Work in pairs to identify attributes and methods for these classes– Activity -2 Sub classes : Teacher , HOD both inherit methods and attributes from Person superclass. Attributes and methods in red are inherited so don’t need to be repeated. Class Attributes Methods Person firstname, lastname, email Fullname Student Firstname, lastname, email, tutor group, year group Studentdetails Teacher HOD

Let us continue after break