Section 4: Interfaces Parsing Data and

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

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.
try { Assert(Life. Real); Assert(Life
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 5: HW6 and Interfaces.
Abstract Classes and Interfaces The objectives of this chapter are: To explore the concept of abstract classes To understand interfaces To understand the.
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.
CS 106 Introduction to Computer Science I 11 / 20 / 2006 Instructor: Michael Eckmann.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Unit 031 Interfaces What is an Interface? Interface Declaration Syntax Implementing Interfaces Using Interfaces as Types Interfaces and Inheritance Interfaces.
Unit 031 Interfaces What is an Interface? Interface Declaration Syntax Implementing Interfaces Using Interfaces as Types Interfaces and Inheritance Interfaces.
UML Class Diagram: class Rectangle
ISE 582: Web Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 4 JAVA Cup.
Abstraction, Inheritance, and Polymorphism in Java.
Inheritance using Java
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Question of the Day  Write valid mathematical equation using: one addition operator (‘+’) one equality operator (‘=’)  Should have equal values.
(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
LECTURE 9: INTERFACES & ABSTRACT CLASSES CSC 212 – Data Structures.
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE Section 5: HW6 and Interfaces Justin Bare and Deric.
UNIT-3 Interfaces & Packages. What is an Interface? An interface is similar to an abstract class with the following exceptions: All methods defined in.
Slides with material from Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 3: HW4, ADTs, and more.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Interfaces CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (see Chapter 9 of.
Lecture 5:Interfaces and Abstract Classes
Abstract classes and interfaces
More About Java and Java How to Program By Deitel & Deitel.
Web Design & Development Lecture 9
Advanced Programming in Java
Advanced Programming in Java
Sixth Lecture ArrayList Abstract Class and Interface
Sections Inheritance and Abstract Classes
University of Central Florida COP 3330 Object Oriented Programming
Chapter 19 Java Data Structures
Interface, Subclass, and Abstract Class Review
Inheritance and Polymorphism
Interface.
UML Class Diagram: class Rectangle
Section 5: HW6 and Interfaces
Section 5: HW6 and Interfaces
Abstract classes and interfaces
Interface.
Interfaces.
Programming in C# CHAPTER - 11
Advanced Java Programming
CSC 113: Computer programming II
Advanced Programming in Java
Inheritance Inheritance is a fundamental Object Oriented concept
Advanced Programming in Java
Section 5: HW6 and Interfaces
Chapter 14 Abstract Classes and Interfaces
Warmup ["hip","hip"] = Hip Hip Array! ???.
Abstract classes and interfaces
Section 5: HW6 and Interfaces
Inheritance Lakshmish Ramaswamy.
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Section 4: Interfaces Parsing Data and SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE

Classes, Objects, and Java Everything(save primatives) is an instance of a class Defines data and operations Every class is part of the same type hierarchy All extend one specified class or Object Inherits superclass fields Every class also defines a type

Problems with Inheritance Performer Perform() (abstract) Dancer Musician Perform() Perform() *Does a beautiful dance* *Sings a soulful song* Michael Jackson Perform() What happens when we call Michael Jackson’s perform()?

Interfaces: Like Skeletons! Pure type declaration public interface Comparable { int compareTo(Object other); } Can contain: Method specifications (implicitly public) Named constants (implicitly public final static) New to Java 8, default method implementations Not normally used for implementation! Cannot create instances of interfaces (similar to abstract classes) (Interfaces are a skeleton)

Michael Jackson’s Situation? Performer Performer Dancer Dancer Singer Singer Dance() *Waltzes away* Default = Sing() *Plays Wonderwall* = Default Perform() *Does a beautiful dance* Default = Perform() *Sings a soulful song* = Default Michael Jackson Perform()

Implementing Interfaces A class can implement one or more interfaces class Kitten implements Pettable, Huggable The implementing class and its instances have the interface type(s) as well as the class type(s) The class must provide or inherit an implementation of all methods defined by the interface(s) Not true for abstract classes

Interface Ideas?

Using Interface Types An interface defines a type, so we can declare variables and parameters of that type A variable with an interface type can refer to an object of any class implementing that type List<String> x = new ArrayList<String>(); void sort(List aList) {…}

Guidelines for Interfaces Provide interfaces for significant types and abstractions Think about the “is-a” relationship Write code using interface types like Map instead of HashMap and TreeMap wherever possible Allows code to work with different implementations later on Clarifies what the code makes use of Both interfaces and classes are appropriate in various circumstances

What about Abstract Classes? Why might you want to use an Abstract Class instead of an Interface?

Parsing Data We’ll look at examples using CSV