20091113-Inheritance-II

20091113-Inheritance-II - CSE115: Introduction to Computer...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements We will return exams some time next week.
Background image of page 2
Agenda Today: Inheritance uses of inheritance overuse of inheritance Coming up: Inheritance overriding of methods (full, partial, none) Primitives More control structures
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Last time We saw two classes extending from a common superclass. Consequences: polymorphism (type hierarachy) reduced code duplication (inheritance)
Background image of page 4
Code duplication a “code smell” package pkg; public class UTA implements TA { private String _name; public UTA( String name ) { _name = name; } public String job() { return "teach recitations"; } public String name() { return _name; } } package pkg; public class GTA implements TA { private String _name; public GTA( String name ) { _name = name; } public String job() { return "grade labs"; } public String name() { return _name; } }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Refactored code package pkg; public class UTA extends AbstractTA { public UTA( String name ) { super(name); } public String job() { return "teach recitations"; } } package pkg; public class GTA extends AbstractTA { public GTA( String name ) { super(name); } public String job() { return "grade labs"; } } package pkg; public abstract class AbstractTA { private String _name; public AbstractTA( String name ) { _name = name; } public abstract String job(); public String name() { return _name; } }
Background image of page 6
Flavors of inheritance Inheritance is used for different purposes:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/13/2011 for the course CSE 115 taught by Professor Decker during the Fall '08 term at SUNY Buffalo.

Page1 / 27

20091113-Inheritance-II - CSE115: Introduction to Computer...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online