Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Advertisements

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 7 Semantics Surely all this is not without.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to.
Chapter 11 Introduction to Programming in C
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 11 Memory Management C makes it easy to shoot.
Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Python Objects and Classes
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
Introduction to Python Week 15. Try It Out! Download Python from Any version will do for this class – By and large they are all mutually.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 4 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case.
Object-Oriented Programming
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
Programming Languages and Paradigms
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Lecture 10: Part 1: OO Issues CS 540 George Mason University.
OBJECT ORIENTED PROGRAMMING (OOP) IN PYTHON David Moodie.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
CSC321: Programming Languages13-1 Programming Languages Tucker and Noonan Chapter 13: Object-Oriented Programming 13.1 Prelude: Abstract Data Types 13.2.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 7 Semantics Ismael: “Surely all this is not.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Types I was eventually persuaded of the need to design programming notations so as to maximize.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
Munster Programming Training
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Object Oriented Design: Identifying Objects
Chapter 6 Object-Oriented Java Script JavaScript, Third Edition.
General Computer Science for Engineers CISC 106 Lecture 04 Dr. John Cavazos Computer and Information Sciences 09/10/2010.
Python Overview  Last week Python 3000 was released  Python 3000 == Python 3.0 == Py3k  Designed to break backwards compatibility with the 2.x.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Programming Languages 2nd edition Tucker and Noonan Chapter 6 Type Systems I was eventually persuaded of the need to design programming notations so as.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 9.4 Java Interfaces. © 2006 Pearson Addison-Wesley. All rights reserved Java does not support multiple inheritance. Interface Characteristics...
Guide to Programming with Python Chapter Eight (Part I) Object Oriented Programming; Classes, constructors, attributes, and methods.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 12 Inheritance and Class Design 1.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
C H A P T E R T H R E E Type Systems and Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
CS-104 Final Exam Review Victor Norman.
CS230 Tutorial Week 3.
Programming Language Concepts (CIS 635)
Copyright © The McGraw-Hill Companies, Inc
Procedural Abstraction Object-Oriented Code
Chapter 3 Image Slides Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Lists in Python.
Chapter R A Review of Basic Concepts and Skills
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Python Tutorial for C Programmer Boontee Kruatrachue Kritawan Siriboon
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Variables, Lists, and Objects
Python Primer 1: Types and Operators
Programming Languages 2nd edition Tucker and Noonan
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © The McGraw-Hill Companies, Inc
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
CHAPTER 6 SKELETAL SYSTEM
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Copyright © 2004 The McGraw-Hill Companies, Inc. All rights reserved.
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Chapter 3 Introduction to Physical Design of Transportation Facilities.
Presentation transcript:

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 13 Object-Oriented Programming I am surprised that ancient and Modern writers have not attributed greater importance to the laws of inheritance... Alexis de Tocqueville

Copyright © 2006 The McGraw-Hill Companies, Inc. Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.3 Smalltalk 13.4 Java 13.5 Python

Copyright © 2006 The McGraw-Hill Companies, Inc Python Multiparadigm –Imperative –Object-orientd –Functional Scripting language Dynamically typed

Copyright © 2006 The McGraw-Hill Companies, Inc. General Characteristics Builtin types: int, float, infinite precision integers, complex numbers, strings,... Data structure –Lists: [1, [2, "allen"], "bob", ] –Hashes: ["Tucker": "Bowdoin", "Noonan": "W&M"] –Tuples: (238111, "allen", "bob") Strings: viewed as list of characters –List operators work on strings

Copyright © 2006 The McGraw-Hill Companies, Inc. Python "less forgiving" than Perl –Cannot do string operations on numbers –Or vice versa –Cannot index past end of list –Must append to end of a list

Copyright © 2006 The McGraw-Hill Companies, Inc. Statements fairly conventional Indentation used for compound statements No $var as in Perl (bareword error) Reference semantics used for assignment Multiple inheritance All methods and instance variables are public. Variables must be set before being referenced. Run time type identification Reflection

Copyright © 2006 The McGraw-Hill Companies, Inc. Examle: Polynomials Represent Polynomials: 3 x 2 + 5x - 7 Representation: #(-7 5 3) Subclass of Magnitude

Copyright © 2006 The McGraw-Hill Companies, Inc. class Polynomial: def __init__(self, coef): """constructor""" self.coefficient = [ ] + coef def degree(self): """Highest power with a non-zero coefficient""" return len(coefficient)

Copyright © 2006 The McGraw-Hill Companies, Inc. def coefficient(self, power): """Coefficient of given power""" if power > len(coefficient): return 0 return coefficient[power] def asList(self): """return copy of coefficient""" return [ ] + coefficient

Copyright © 2006 The McGraw-Hill Companies, Inc. def __eq__(self, aPoly): """return self == aPoly""" return coefficient == aPoly.asList( ) def __ne__(self, aPoly): """return self <> aPoly.asList( )""" return coefficient <> aPoly.asList( )

Copyright © 2006 The McGraw-Hill Companies, Inc. def __str__(self): """return string representation""" r = "" p = len(coefficient) + 1 while p > 0: p = p - 1 if coefficient[p] == 0: continue if p < len(coefficient): r = r + "+" r = r + str(coefficient[p]) if p == 0: continue r = r + "x" if p <= 1: continue