Object Oriented Design and Classes. What is a class? Programming mechanism to support OOD Data and the methods that operate on that data – collectively.

Slides:



Advertisements
Similar presentations
CIT 590 Intro to Programming Classes. Schedule change The upcoming HW (HW6) is your last major Python HW. It will involve object oriented programming.
Advertisements

Recitation 5 Programming for Engineers in Python.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
1 Classes Object-oriented programming: Model the problem as a collection of objects that have certain attributes and interact with one another and/or the.
Object Oriented Design and Classes
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
Chapter 2 – An Introduction to Objects and Classes Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
TA: Nouf Al-Harbi NoufNaief.net :::
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Classes. Object-Oriented Design Method for designing computer programs Consider “objects” interacting in the program –Example: a zoo, a gradebook.
Classes. What is a class? Data and the functions (methods) that operate on that data – collectively called members –Example: bank account class Provide.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Classes and Objects Overview l Classes and Objects l Constructors l Implicit Constructors l Overloading methods this keyword l public, private and protected.
INFO 206 Lab Exercise 1 Introduction to Classes and Objects 1/18/2012i206 Lab 1 - Exercise1.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
CIT 590 Intro to Programming Style Classes. Remember to finish up findAllCISCourses.py.
Computer Science 111 Fundamentals of Programming I More Data Modeling.
Classes CS 21a: Introduction to Computing I First Semester,
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
CS61A Lecture 13 Object-Oriented Programming Jom Magrotker UC Berkeley EECS July 10, 2012.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
1 Warm-Up Problem Just like with primitive data types (int, double, etc.), we can create arrays of objects. ex: bankAccount employees[100]; Problem: It’s.
Classes: Member Functions and Implementation November 22, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
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.
Simple Interest. Simple Interest – * the amount of money you must pay back for borrowing money from a bank or on a credit card or * the amount of money.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Stakeholders Inland revenue Banks Shareholders Employees Suppliers Customers.
Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Object Oriented Programming In Python
93 4/11/98 CSE 143 Class Constructors [Sections ]
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 3: An Introduction to Classes 1 Chapter 3 An Introduction to Classes.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
 An object is basically anything in the world that can be created and manipulated by a program.  Examples: dog, school, person, password, bank account,
Object-Oriented Programming (OOP) in Python References: Chapter 8.
Interest Applications - To solve problems involving interest.
CSC 231: Introduction to Data Structures Python and Objects – Day 3 Dr. Curry Guinn.
Topics Procedural and Object-Oriented Programming Classes
Classes Object-oriented programming: Example: Bank transactions
Implementing Classes Yonglei Tao.
Fundamentals of Programming I More Data Modeling
CSC 131: Introduction to Computer Science
CASH & Bank Reconciliation
Object-Oriented Programming: Classes and Objects
Engineering Computing
Object Oriented Programming
Chapter Three - Implementing Classes
Adapted from slides by Marty Stepp and Stuart Reges
3.7 Variable Assignment Recall instance variables in Python:
Fundamentals of Programming I Commonly Used Methods More Modeling
15-110: Principles of Computing
Fundamentals of Programming I More Data Modeling
JAVA CLASSES.
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
CSE 231 Lab 11.
Lecture 18 Python OOP.
Agenda About Homework for BPJ lesson 15 Overloading constructor
By Rajanikanth B Classes in Java By Rajanikanth B
Classes.
Presentation transcript:

Object Oriented Design and Classes

What is a class? Programming mechanism to support OOD Data and the methods that operate on that data – collectively called members –Example: bank account class Provide structure for organizing programs

Methods Methods operate on data –accessors – read data, provide access to data but do not change it –mutators – change data examples from bank account, zoo –constructor – builds a new object An object in an instance of a class –class is a blueprint for objects

BankAccount Class class BankAccount: def __init__(self, initial_balance): self.balance = initial_balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount def checkBalance(self): print "Balance: ", self.balance

BankAccount Class def __init__(self, initial_balance): self.balance = initial_balance __init__ method is the constructor Used to initialize members of the object First parameter is self – the object on which the method/constructor is called Use dot notation (.) to reference members of the object

BankAccount Class def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount Deposit and withdraw are mutators –they modify the data member balance First parameter is self Like functions, methods can take any number of parameters

BankAccount Class def checkBalance(self): print "Balance: ", self.balance checkBalance does not modify data members

Creating and Using Objects b = BankAccount(500) //Name = Type(constructor parameters)

Creating and Using Objects b = BankAccount(500) //Name = Type(constructor parameters) //how would you withdraw funds? b.withdraw(500) //object_name.method_name(params)

Composing Objects An object can have a reference to another object class Name: def __init__(self, first, last): self.first = first self.last = last def printName(self): print "Name: ", self.first, " ", self.last class Employee: def __init__(self, first, last, pay): self.name = Name(first, last) self.pay = pay def printEmployee(self): self.name.printName() print "\tPay rate: ", self.pay