40-244 – Advanced Programming P ROGRAMMING IN Lecture 16 Interfaces.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Object Oriented Programming
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
Inheritance Lakshmish Ramaswamy. Example A Rectangle class with area method A Circle class with area method Array containing references to circles & rectangles.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis 1.
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Lecture 8 CS203. Implementation of Data Structures 2 In the last couple of weeks, we have covered various data structures that are implemented in the.
Interface & Abstract Class. Interface Definition All method in an interface are abstract methods. Methods are declared without the implementation part.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
CSE 115 Week 10 March , Announcements March 21 – Lab 7 Q & A in lecture March 21 – Lab 7 Q & A in lecture March 26 – Exam 7 March 26 – Exam.
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
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.
Interfaces and Inner Classes. What is an Interface?  What is “presented to the user”?  The public part of a class?  What is the substance of an interface?
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides created by Marty Stepp
Inheritance and Polymorphism CS351 – Programming Paradigms.
Abstract classes and Interfaces. Abstract classes.
Inheritance using Java
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
Lecture 3 Casting Abstract Classes and Methods Interfaces.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
Lists and the Collection Interface Review inheritance & collections.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
Inheritance Objectives: Creating new classes from existing classes The protected modifier Creating class hierarchies Abstract classes Indirect visibility.
Inheritance CSCE 190 – Java Instructor: Joel Gompert Mon, August 2, 2004.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
Class Relationships Lecture Oo07 Generalization Relationships.
Object Oriented Programming in Java Habib Rostami Lecture 7.
Further Abstraction Techniques Chapter 10. Abstract Classes There are times when you do not want someone to be able to make an object of your class. For.
CS 116 Object Oriented Programming II Lecture 9 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
1 Inheritance One of the goals of object oriented programming is code reuse. Inheritance is one mechanism for accomplishing code reuse. It allows us to.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Programming in Java: lecture 7
Web Design & Development Lecture 9
Advanced Programming in Java
Advanced Programming in Java
Sixth Lecture ArrayList Abstract Class and Interface
CS240: Advanced Programming Concepts
CSE 143 Lecture 27: Advanced List Implementation
Lecture 26: Advanced List Implementation
Interfaces.
OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS
Advanced Java Programming
Advanced Programming in Java
Advanced Programming in Java
COS 260 DAY 23 Tony Gauvin.
COS 260 DAY 23 Tony Gauvin.
CSE 143 Lecture 21 Advanced List Implementation
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

– Advanced Programming P ROGRAMMING IN Lecture 16 Interfaces

What We Will Learn Typing Viewpoint Abstract Classes as types The problem with multiple inheritance Interfaces

Typing Viewpoint Recall that every object has Interface Implementation Interface is the type Implementation is the code

Inheritance and Typing Inheritance decouples type from code Same code works for several types Objects decide how to do their own work

An Example List is a type Its operations include: adding an object removing an object accessing a specific element May be implemented using linked-lists or arrays, etc.

The List Abstract Class public abstract class List { public abstract void add(Object o); public abstract void remove(int index); public abstract Object get(int index); } public class LinkedList extends List { public void add(Object o) {...}... }

Having Multiple Types What if we want to view a class from different perspectives? Example: We may want to define a ListView class It is both a List and a View (something that can be drawn on screen)

Multiple Inheritance From the previous example, there is a need for multiple inheritance Multiple inheritance means having multiple superclasses ListView ListView

No Multiple Inheritance! Java like some other languages doesn't support multiple inheritance Suppose A has a method m which B and C override it What happens to the m that D inherits? interface of m is the same in all of them But the implementation differs BC D A

The Problem Subclassing is the implementation or code inheritance Since the superclass may define body of some methods What we needed from the ListView example was the interface inheritance

The Solution Having something that just defines interface public interface List { void add(Object o); void remove(int index); Object get(int index); } public class LinkedList implements List { public void add(Object o) {...}... }

Interfaces Can be used as a type name void printAll(List l) {...} All methods are public by default No method can have implementations All fields are considered static final So there is no implementation in it

Some Examples java.util.List java.awt.event.MouseListener java.awt.event.KeyListener public class ListView implements List, View {... }

Interface Inheritance Can be extended using inheritance Can have multiple superinterfaces