CS 210 Introduction to OO Design August 24, 2006

Slides:



Advertisements
Similar presentations
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
Advertisements

ABSTRACT CLASSES AND INTERFACES. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method without.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
Chapter 10: Introduction to Inheritance
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Science By Reba Wiggins
15-Jun-15 Abstract Classes and Interfaces. 2 Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
CS 106 Introduction to Computer Science I 11 / 28 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 11 / 15 / 2006 Instructor: Michael Eckmann.
Abstract Classes and Interfaces. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method without.
UML Class Diagram: class Rectangle
Object-Orientated Design and Programming Unit 9: Abstract Classes and Interfaces Jin Sa.
Abstract Classes b b An abstract class is a placeholder in a class hierarchy that represents a generic concept b b An abstract class cannot be instantiated.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 17 Animated Version Generics and Type Safety.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
Inheritance in C++ CS-1030 Dr. Mark L. Hornick.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Polymorphism & Interfaces
PET ANIMALS.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Objects and Classes Abstract Classes and Interface Sanjaya Karunasena
This is a song about food chains, food chains, food chains This is a song about food chains and living things on Earth.
Java Programming Dr. Randy Kaplan. Abstract Classes and Methods.
Abstract Classes and Interfaces 5-Dec-15. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
What You’re Called and What You Eat. Animals need to eat.  Here’s a fact you know is true every time your tummy growls: animals need to eat. Some animals.
Use the word bank given to determine if each organism is a carnivore, herbivore, omnivore.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
CS 106 Introduction to Computer Science I 04 / 18 / 2008 Instructor: Michael Eckmann.
Producer Consumer Herbivore Omnivore Carnivore. 23. producer- An organism that can make its own food Any organism that can perform photosynthesis is a.
Interfaces and Polymorphism CS 162 (Summer 2009).
More Inheritance 7/2/2009. Important Dates Project 1 - Check-off – Thursday 7/02/2009 ready BEFORE lab Review Session – Sunday 7/05/2009 – 306 Soda 1-4pm.
© 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.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
Food Web & Food Chains Quiz 1. an animal that eats only other animals A. consumer B. herbivore C. carnivore D. omnivore.
 There are 2 ways that organisms obtain their energy 1. Producer (aka Autotroph) 2. Consumer (aka Heterotroph)
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
IN 076 Pola Desain Perangkat Lunak Dosen: Hapnes Toba Oscar Karnalim
By: Ms. Alonge. Instructions Select the answers to the best of your knowledge If you don’t get it right the first time, you will be asked to try again!
Essential Question Lesson 2
Comp1004: Object Oriented Design I Abstract Classes and Interfaces.
Coming up A quick word about abstract How a class interfaces
Modern Programming Tools And Techniques-I
Advanced Programming in Java
Advanced Programming in Java
Carnivores, herbivores and omnivores
Lecture 12 Inheritance.
Abstract Classes and Interfaces
Abstract Classes and Interfaces
Interfaces.
One class is an extension of another.
CS250 Introduction to Computer Science II
UML Class Diagram: class Rectangle
Class vs Abstract vs Interface
Interfaces.
One class is an extension of another.
Science By Reba Wiggins
How do organisms get energy?
Mammals.
Science By Reba Wiggins
Food Chains.
Inheritance, Superclasses, Subclasses
Abstract Classes Page
Java Inheritance.
Advanced Programming in Java
FOOD CHAIN A food chain shows how each living thing gets its food.
Interfaces and Abstract Classes
Presentation transcript:

CS 210 Introduction to OO Design August 24,

Polymorphism Many faces of an Object

Polymorphism Ability to communicate to objects that don’t even exist when initial design was created! Use methods defined in parent class on child class Object 1 print object display object pdf object print object display object Word object print object display object new object print object display object

A simple example* animal type eats sound herbivore type eats sound carnivore type eats sound omnivore type eats sound elephant type eats sound lion type eats sound bear type eats sound Does it make sense to instantiate these classes? *Adapted from Head First Java, O’Reilly Press

Abstract Classes When it does not make sense to instantiate a particular class, but it makes sense to define them for the purpose of organization, use an “Abstract” class. Abstract class cannot be instantiated – they can only be “extended” Abstract classes can have abstract methods as well.. These methods have to be implemented in the concrete classes.

Role of Interfaces How does one deal with multiple inheritance?

Multiple Inheritance animal eats sound cat eats sound dog eats sound hippo eats sound pet Rollover?

Problem with multiple inheritance* Digirecord burn() DVDBurner burn() CDBurner burn() ComboBurner burn() *Adapted from Head First Java, O’Reilly Press

Java approach Use Interfaces Classes can “extend” classes and they can “implement” interfaces.

Multiple Inheritance – make Pet class an interface animal eats sound cat eats sound dog eats sound hippo eats sound pet Rollover?