November 28, 2005ICP: Chapter 9: Object Oriented Programming 1 Introduction to Computer Programming Chapter 9: Object Oriented Programming Michael Scherger.

Slides:



Advertisements
Similar presentations
1 CSC 221: Introduction to Programming Fall 2011 List comprehensions & objects building strings & lists comprehensions conditional comprehensions example:
Advertisements

Topics in Python Blackjack & TKinter
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
CS 106 Introduction to Computer Science I 11 / 13 / 2006 Instructor: Michael Eckmann.
Object-Oriented Analysis and Design
Elevens Lab Student Material – on website
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
ECS15 sequence. Sequences  There are three kinds of sequences in Python: Strings – we use these a lot. “albatross” Lists – we saw those last time, they.
CS 106 Introduction to Computer Science I 11 / 19 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 21 / 2008 Instructor: Michael Eckmann.
Chapter 5 Black Jack. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 5-2 Chapter Objectives Provide a case study example from problem statement.
Chapter 10 Classes Continued
CS 106 Introduction to Computer Science I 04 / 28 / 2010 Instructor: Michael Eckmann.
Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Exercise Session 7.
JokerStars: Online Card Playing William Sanville Milestone 4.
CS 106 Introduction to Computer Science I 04 / 07 / 2010 Instructor: Michael Eckmann.
o Simulate a deck of playing cards o Shuffle the deck o Deal (5) cards into the hand o Turn over the first card o The user must guess whether the next.
o Simulate a deck of playing cards o Shuffle the deck o Deal 5 cards into the hand o Turn over the first card o The user must guess whether the next card.
C++ fundamentals.
1.11 Introduction to OOP academy.zariba.com 1. Lecture Content 1.What is OOP and why use it? 2.Classes and objects 3.Static classes 4.Properties, fields.
Fundamentals of Python: From First Programs Through Data Structures
BACS 287 Basics of Object-Oriented Programming 1.
Object-Oriented Programming: Inheritance Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Guide to Programming with Python Chapter Nine Working with/Creating Modules.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Poker UML and ADT design plan.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
November 15, 2005ICP: Chapter 7: Files and Exceptions 1 Introduction to Computer Programming Chapter 7: Files and Exceptions Michael Scherger Department.
Inner and Anonymous Classes Though you are captive in the OO paradigm, you can use inner classes and anonymous classes to get around this constraint and.
Computer Science 111 Fundamentals of Programming I More Data Modeling.
CPSC1301 Computer Science 1 Chapter 11 Creating Classes part 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Java Inheritance.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
August 29, 2005ICP: Chapter 1: Introduction to Python Programming 1 Introduction to Computer Programming Chapter 1: Introduction to Python Programming.
Guide to Programming with Python
Object Oriented Design. Object-Oriented Design Method for designing computer programs –Useful for thinking about large problems Consider “objects” interacting.
CSE 501N Fall ‘09 14: Inheritance 20 October 2009 Nick Leidenfrost.
Domain Modeling Part2: Domain Class Diagram Chapter 4 pp part 2 1.
CS 106 Introduction to Computer Science I 04 / 23 / 2010 Instructor: Michael Eckmann.
Guide to Programming with Python Week 11 Chapter Nine Inheritance Working with multiple objects.
 m C r =m!/r!(m-r)!  Property: m C r = m C (m-r)  Example: ◦ If you have 10 pens, all in different colors, and you want to bring two of them to class,
M1G Introduction to Programming 2 5. Completing the program.
Object Oriented Programming: Inheritance Chapter 9.
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Copyright 2006 Oxford Consulting, Ltd1 January Introduction to C++ Programming is taking A problem Find the area of a rectangle A set of data.
© 2007 Lawrenceville Press Slide 1 Chapter 9 Inheritance  One class is an extension of another.  Allows a class to define a specialized type of an existing.
Java Software Solutions Lewis and Loftus Chapter 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. 1 Inheritance -- Introduction.
CS 210 Introduction to OO Design August 24, 2006
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
Guide to Programming with Python
The Movement To Objects
Lecture 12 Inheritance.
Python First Edition STARTING OUT WITH Chapter 10 Inheritance
One class is an extension of another.
Chapter 5 Black Jack.
Testing Object-Oriented Software Concepts and Definitions
Chapter 9 Pointers Objectives
3 Fundamentals of Object-Oriented Programming
One class is an extension of another.
Week 6 Object-Oriented Programming (2): Polymorphism
Inheritance and Polymorphism
Fundaments of Game Design
Introduction to Computer Science
Computer Science II for Majors
Presentation transcript:

November 28, 2005ICP: Chapter 9: Object Oriented Programming 1 Introduction to Computer Programming Chapter 9: Object Oriented Programming Michael Scherger Department of Computer Science Kent State University

November 28, 2005ICP: Chapter 9: Object Oriented Programming 2 Contents Creating objects of different classes in the same program Allow objects to communicate with each other Combining classes Inheritance Overriding method definitions

November 28, 2005ICP: Chapter 9: Object Oriented Programming 3 Blackjack Game Example: Blackjack GameBlackjack Game –Imports: Cards, GamesCardsGames

November 28, 2005ICP: Chapter 9: Object Oriented Programming 4 Sending and Receiving Messages Sending a Message –When one object tells another object to perform some action or function hero = Player() invader = Alien() def hero.blast(self, enemy): enemy.die()

November 28, 2005ICP: Chapter 9: Object Oriented Programming 5 Sending and Receiving Messages Receiving a Message –The action of executing the receiving the message from the calling object and performing the appropriate method

November 28, 2005ICP: Chapter 9: Object Oriented Programming 6 Sending and Receiving Messages Example: Alien Blaster ProgramAlien Blaster Program

November 28, 2005ICP: Chapter 9: Object Oriented Programming 7 Combining Objects Objects can be “combined” to form other objects or collections of objects –A Car Class consists of individual Tires, Engine, Seats,…individual parts that make up the whole –A Zoo Class has a collection of other animals: Lions, Tigers, Bears, etc –A FreeCheckingAccount is a type of CheckingAccount is a type of Account

November 28, 2005ICP: Chapter 9: Object Oriented Programming 8 Combining Objects Creating the Card Class –A playing card has a “rank” and a “suit” Constants Constructor initializes a single Card __str__ is used to print out the rank and suit as a two character string

November 28, 2005ICP: Chapter 9: Object Oriented Programming 9 Combining Objects Creating the Hand Class –The Hand class is a collection of Card objects Uses a list __str__ prints out the contents of each hand clear() clears the hand of cards add() adds a card to the list give() gives a card to another hand

November 28, 2005ICP: Chapter 9: Object Oriented Programming 10 Combining Objects Using Card Objects Combining Card Objects Using a Hand Object Example: Playing Cards ProgramPlaying Cards Program

November 28, 2005ICP: Chapter 9: Object Oriented Programming 11 Using Inheritance to Create New Classes Create new classes from old –“is_a” relationship –Single inheritance –Multiple inheritance

November 28, 2005ICP: Chapter 9: Object Oriented Programming 12 Extending a Class Through Inheritance Creating a Base Class –Same base classes as before Inheriting from a Base Class –A “deck” is a special type of hand It has 52 cards (populate method) You can deal from a deck You can shuffle a deck

November 28, 2005ICP: Chapter 9: Object Oriented Programming 13 Extending a Class Through Inheritance Example: Playing Cards 2.0 ProgramPlaying Cards 2.0 Program

November 28, 2005ICP: Chapter 9: Object Oriented Programming 14 Altering the Behavior of Inherited Methods Creating a Base Class

November 28, 2005ICP: Chapter 9: Object Oriented Programming 15 Altering the Behavior of Inherited Methods Overriding Base Class Methods

November 28, 2005ICP: Chapter 9: Object Oriented Programming 16 Altering the Behavior of Inherited Methods Invoking Base Class Methods

November 28, 2005ICP: Chapter 9: Object Oriented Programming 17 Altering the Behavior of Inherited Methods Using the Derived Classes

November 28, 2005ICP: Chapter 9: Object Oriented Programming 18 Altering the Behavior of Inherited Methods Example: Playing Cards 3.0 ProgramPlaying Cards 3.0 Program

November 28, 2005ICP: Chapter 9: Object Oriented Programming 19 Understanding Polymorphism

November 28, 2005ICP: Chapter 9: Object Oriented Programming 20 Creating Modules Writing Modules

November 28, 2005ICP: Chapter 9: Object Oriented Programming 21 Creating Modules Importing Modules

November 28, 2005ICP: Chapter 9: Object Oriented Programming 22 Creating Modules Using Imported Functions and Classes

November 28, 2005ICP: Chapter 9: Object Oriented Programming 23 Creating Modules Example: Simple Game ProgramSimple Game Program –Imports: GamesGames

November 28, 2005ICP: Chapter 9: Object Oriented Programming 24 Blackjack Game (Again) Example: Blackjack GameBlackjack Game –Imports: Cards, GamesCardsGames