Object Oriented Design and Classes

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

Class Relationships Part 1: Composition and Association CS 21a: Introduction to Computing I First Semester,
Recitation 5 Programming for Engineers in Python.
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.
Lab 10: Bank Account II Transaction List, error checking & aggregation.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
Chapter 3 – Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To.
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.
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.
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.
Object Oriented Design and Classes. What is a class? Programming mechanism to support OOD Data and the methods that operate on that data – collectively.
ACM/JETT Workshop - August 4-5, Object-Oriented Basics & Design.
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.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
Classes CS 21a: Introduction to Computing I First Semester,
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.
Classes 1 COMPSCI 105 S Principles of Computer Science.
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.
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++;
Check Lingo A personal check is a written form that states a written amount to withdraw directly from the payer’s account.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 3: An Introduction to Classes 1 Chapter 3 An Introduction to Classes.
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
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.
Inf 43: Introduction to Software Engineering May 7, 2016.
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
Engineering Computing
Chapter Three - Implementing Classes
Object-oriented Design in Processing
Adapted from slides by Marty Stepp and Stuart Reges
CS2011 Introduction to Programming I Objects and Classes
Object-oriented Design in Processing
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
Object-oriented Design in Processing
Lecture 18 Python OOP.
Classes.
Object-oriented Design in Processing
Presentation transcript:

Object Oriented Design and Classes

Exercises Design a phone book program. Your program should keep track of the name and phone number of your contacts. You should be able to add new contacts to your phone book and view your phone book.

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 An object in an instance of a class 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

Exercises Implement your phone book program.