Object Oriented Programming In Python

Slides:



Advertisements
Similar presentations
Object-Oriented Programming
Advertisements

Python Mini-Course University of Oklahoma Department of Psychology Lesson 26 Classes and Objects 6/16/09 Python Mini-Course: Lesson 26 1.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
From datetime import * class StopWatch(object): def __init__(self): now = datetime.now() self.hr = now.hour self.min = now.minute self.sec = now.second.
INFO 206 Lab Exercise 1 Introduction to Classes and Objects 1/18/2012i206 Lab 1 - Exercise1.
Object-oriented Programming Concepts
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
Guide to Programming with Python
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
I210 review (for final exam) Fall 2011, IUB. What’s in the Final Exam Multiple Choice (5) Short Answer (5) Program Completion (3) Note: A single-sided.
Guide to Programming with Python Chapter Eight (Part II) Object encapsulation, privacy, properties; Critter Caretaker game.
What is Object-Oriented Programming?. Objects – Variables and Logic inside "Objects", not standalone code – Objects contain related variables and functions.
COSC 1306—COMPUTER SCIENCE AND PROGRAMMING DATA ABSTRACTION Jehan-François Pâris
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
1 Survey of Computer Science CSCI 110, Spring 2011 Lecture 14 Recursion.
Object Oriented Programming Lecturer: Andreas P. Adi
BCS 2143 Introduction to Object Oriented and Software Development.
Object Oriented Programming CS160 - OOP. Objects Objects are a Objects are a way to organize and conceptualize a program as a set of interacting objects.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Object-Oriented Programming and Classes Chapter 7.
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 18 What are programs for? Classes and Objects.
Guide to Programming with Python Week 11 Chapter Nine Inheritance Working with multiple objects.
CLASSES Python Workshop. Introduction  Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax.
PYTHON OBJECTS & CLASSES. What is an object? The abstract idea of anything What is in an object: Attributes Characteristics Represented by internal variables.
OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.
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.
Basics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Object Oriented Programing (OOP)
Object Oriented Programming: Inheritance Chapter 9.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
Reconcile a Bank Statement UNIT 1 LESSON 2. First… some definitions  Bank statement  Shows all transactions that have occurred during the month  Statement.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
CSCI 171 Presentation 15 Introduction to Object–Oriented Programming (OOP) in C++
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
Object-Oriented Programming (OOP) in Python References: Chapter 8.
INTRODUCTION CSE 470 : Software Engineering. Goals of Software Engineering To produce software that is absolutely correct. To produce software with minimum.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Object Oriented Programming: Inheritance
What is an Object Objects are key to understanding object-oriented technology. An object can be considered a "thing" that can perform a set of related.
Guide to Programming with Python
Object-Oriented Programming (OOP) in Python
Classes and OOP.
About the Presentations
OBJECT ORIENTED PROGRAMMING overview
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Programming
Object-oriented programming
3 Fundamentals of Object-Oriented Programming
Guide to Programming with Python
Teach A-Level Computer Science: Object-Oriented Programming in Python
Object-Oriented Programming
Introduction to Objects
Guide to Programming with Python Book is by Michael Dawson
COP 3330 Object-oriented Programming in C++
CIS16 Application Development and Programming using Visual Basic.net
Object-Oriented Programming
Workshop for Programming And Systems Management Teachers
By Rajanikanth B OOP Concepts By Rajanikanth B
CSE 231 Lab 11.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Object Oriented Programming In Python

Understanding Object Oriented Programming, or OOP So far, you have written Python programs in a “Top Down” fashion using functions Now we will learn a new way building and thinking about building software OOP lets you represent real-life objects as software objects You will combine characteristics (called attributes) and behaviors (called methods)

Alien Spacecraft Example If you were to build an alien spacecraft, what would be it’s attributes and behaviors?

Alien Spacecraft Example Attributes: Location, fuel level, engine temperature, current velocity, current direction Behaviors: Move forward, move backward, move up, move down, fire weapons, teleport

Objects and Classes Objects are created (or instantiated in OOP- Speak) from a definition called a class Classes are like blueprints. A class isn’t an object; it is a design for one A builder can create many houses from one set of blueprints A programmer can create many objects from one class

More on Objects and Classes Separate objects can have separate attribute values Just as two houses built from the same blueprint can be decorated differently, two objects of the same class can have their own attribute values

Bank Account Example A bank has one checking account class Attributes: Name, account number, date created, balance Methods: Make deposit, make withdrawl Two objects can be instantiated for two different customers. Each may have their own account number and balance

Simple Python Example class Critter(object) : def talk(self): print("Hi! I am a Critter") def main(): crit = Critter() crit.talk() main() Output: Hi! I am a Critter

Creating A Constructor A constructor is automatically called when the object is instantiated class Critter(object) : def __init__(self): print("A new critter has been born!") def talk(self): print("Hi! I am a Critter") def main(): crit = Critter() crit.talk() main()

Creating Multiple Objects class Critter(object) : def __init__(self): print("A new critter has been born!") def talk(self): print("Hi! I am a Critter") def main(): crit1 = Critter() crit1.talk() crit2 = Critter() crit2.talk() main()

Using Attributes You can have attributes created and initialized when an object is instantiated class Critter(object) : def __init__(self, name): print("A new critter has been born!") self.name = name def talk(self): print("Hi! I am a ", self.name, " Critter") def main(): crit1 = Critter("Dog") crit1.talk() crit2 = Critter("Cat") crit2.talk() main()

Why is OOP important? Makes complex code easier to develop, more reliable, more maintainable and generally better Encapsulation – Lets you change the implementation of an object without affecting other code

Why is oop important? Polymorphism - Lets you have different functions, all with the same name, all doing the same job, but on different data Inheritance – You can write a set of functions and then expand them in different directions without changing or copying them