David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 11: Subtyping and Inheritance.

Slides:



Advertisements
Similar presentations
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 20: Hair Dryer Attacks Image.
Advertisements

Cs2220: Engineering Software Class 10: Generic Datatypes Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 13: Concurring Concurrently.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 6: Reasoning about Data Abstractions.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 16: Concurrent Programming.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 23: Inheritance.
Inheritance Inheritance Reserved word protected Reserved word super
CSE341: Programming Languages Lecture 26 Subtyping for OOP Dan Grossman Fall 2011.
Object Interaction 1 Creating cooperating objects.
Lecture 24: Gödel’s Proof CS150: Computer Science
CSCI-383 Object-Oriented Programming & Design Lecture 15.
CSSE501 Object-Oriented Development
Class 24: Programming with Objects University of Virginia cs1120 David Evans.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 28: Implementing Interpreters.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Cs2220: Engineering Software Class 11: Subtyping and Inheritance Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 12: Subtyping and Inheritance.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
Cs205: engineering software university of virginia fall 2006 Data Abstraction David Evans
1 Object-Oriented Software Engineering CS Interfaces Interfaces are contracts Contracts between software groups Defines how software interacts with.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 3: Rules of Evaluation.
Fall 2010 UVa David Evans cs2220: Engineering Software Class 28: Past and Future.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 12: Subtyping Rules What’s the.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 20: Objects I invented the term Object-
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
Cs205: engineering software university of virginia fall 2006 David Evans Substitution Principle.
Cs205: engineering software university of virginia fall 2006 Introducing Java David Evans Don’t forget to your registration.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 14: Substitution Principle.
Cs2220: Engineering Software Class 3: Java Semantics Fall 2010 University of Virginia David Evans.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 16: Smalltalking about Objects.
Cs205: engineering software university of virginia fall 2006 Subtyping and Inheritance David Evans Quiz Friday: classes through.
CS 180 Problem Solving and Object Oriented Programming Fall 2010 Notes for Week 9: Oct 18-22, 2010 Aditya Mathur Department of Computer Science Purdue.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 9: Designing Exceptionally.
Cs2220: Engineering Software Class 12: Substitution Principle Fall 2010 University of Virginia David Evans.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 8: Designing for Indestructability.
Lecture 3: Rules of Evaluation CS150: Computer Science
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
1 COS 260 DAY 18 Tony Gauvin. 2 Agenda Questions? 7 th Mini quiz Graded –Good results 8 th Mini Quiz –Chap 8  Next class Assignment 4 Due Assignment.
Cs205: engineering software university of virginia fall 2006 Programming Exceptionally David Evans
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 22: Objectifying Objects.
Recitation 7 Godfrey Tan March 21, Administrivia PS6 due Tuesday right after break Final Project descriptions will be handed out Monday after break.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 7: A Tale of Two Graphs (and.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
1 Computer Science 1021 Programming in Java Geoff Draper University of Utah.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 21: Inheritance.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 12: Behavioral Subtyping.
CSCI 383 Object-Oriented Programming & Design Lecture 15 Martin van Bommel.
Lecture 4: Metacircles Eval Apply David Evans
Programming in Java: lecture 7
Sections Inheritance and Abstract Classes
Design David Evans cs205: engineering software
Class 22: Inheritance CS150: Computer Science University of Virginia
Lecture 15: Using Low-Level Languages CS201j: Engineering Software
CS230 Tutorial Week 3.
Subtyping Rules David Evans cs205: engineering software BlackBear
Lecture 15: Concurring Concurrently CS201j: Engineering Software
Lecture 21: Inheritance CS200: Computer Science University of Virginia
Lecture 9: Exceptions in Java CS201j: Engineering Software
Lecture 7: A Tale of Two Graphs CS201j: Engineering Software
Lecture 4: Data Abstraction CS201j: Engineering Software
Lecture 18: Deep C Garbage Collection CS201j: Engineering Software
Lecture 10: Using Object-Oriented Languages
Lecture 3: Rules of Evaluation CS200: Computer Science
Lecture 13: Subtyping Rules Killer Bear Climber
Reasoning about Data Abstractions
Presentation transcript:

David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 11: Subtyping and Inheritance

7 October 2003CS 201J Fall Menu Quiz Results Subtyping Inheritance

7 October 2003CS 201J Fall Class Speed

7 October 2003CS 201J Fall Problem Set 5 Teams

7 October 2003CS 201J Fall Read PS3 Comments 6 of these also said the class is going too fast

7 October 2003CS 201J Fall Still in course if not required?

7 October 2003CS 201J Fall Sections

7 October 2003CS 201J Fall Comments “I’m still not convinced why we focus more time on programming concepts (invariants, requires, etc…) instead of code. I’d rather see problem sets with more implementation of code and less writing/methodical work. I just feel there is so much to Java we could be implementing and learning.” Why not focus more on learning Java? - Some of you will be professional programmers Will need to program in lots of other languages Will need to be better than average programmers - Some of you won’t want to program again after this class Concepts apply to more than just programming: whatever you design will benefit from abstraction, invariants, specifications, notions of subtyping/inheritance, understanding concurrency, etc. - As students at a liberal arts institution, you should be learning intellectually valuable things, not temporary skills

7 October 2003CS 201J Fall Comments Spend more time on Java syntax, need to cover Java more, etc. –Two weeks ago you were asked, “send any questions you have about Java programming” –Only 2 people sent any questions More TAs –Only 2-3 people at each of the lab hours Sunday and Monday!

7 October 2003CS 201J Fall Subtyping

7 October 2003CS 201J Fall Subtyping Cell ConwayLifeCell ConwayLifeCell is a subtype of Cell Cell is a supertype of ConwayLifeCell ConwayLifeCell ≤ Cell

7 October 2003CS 201J Fall Subtype Substitution If B is a subtype of A, everywhere the code expects an A, a B can be used instead Examples: Cell c = c1; c1 must be a subtype of Cell (note A is a subtype of A) Cell c = new ConwayLifeCell (); ConwayLifeCell c = new Cell ();

7 October 2003CS 201J Fall Subtype Examples java.util.Vector: public void addElement (Object obj); public class StringSet { Vector elements; public void insert (String s) { elements.addElement (s); } Why we can use a String where an Object is expected?

7 October 2003CS 201J Fall Java’s Type Hierarchy Object String Cell ConwayLifeCell Object is the ultimate supertype of every object type.

7 October 2003CS 201J Fall Java 3D Class Hierarchy Diagram RotationPathInterpolator PathInterpolator Interpolator Selector Node Leaf SceneGraphObject Not at all uncommon to have class hierarchies like this!

7 October 2003CS 201J Fall Subtype Examples java.util.Vector: public void addElement (Object obj); public class IntSet { Vector elements; public void insert (int x) { elements.addElement (x); } Primitive types are not subtypes of Object. elements.addElement (new Integer (x)); But Integer is…

7 October 2003CS 201J Fall Inheritance To implement a subtype, it is often useful to use the implementation of its supertype This is also called “subclassing” In Java: class B extends A B is a subtype of A B inherits from A class C implements F C is a subtype of F both subtyping and inheritance just subtyping

7 October 2003CS 201J Fall Charge Subtyping –Allow one type to be used where another type is expected Inheritance –Reuse implementation of the supertype to implement a subtype Thursday: –When is it safe to say B is a subtype of A?