CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Linked Lists Chapter 4.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
CS18000: Problem Solving and Object-Oriented Programming.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Creating Classes from Other Classes Chapter 2 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
1 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Creating Classes from Other Classes Chapter 2. 2 Chapter Contents Composition Adapters Inheritance Invoking constructors from within constructors Private.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
CS 2511 Fall  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance  Polymorphism.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
Classes in C++ Bryce Boe 2012/08/15 CS32, Summer 2012 B.
Multiple Choice Solutions True/False a c b e d   T F.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
MIT AITI 2002 Abstract Classes, Interfaces. Abstract Classes What is an abstract class? An abstract class is a class in which one or more methods is declared,
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
CSC 508 – Theory of Programming Languages, Spring, 2009 Week 3: Data Abstraction and Object Orientation.
Object Based Programming Chapter 8. 2 In This Chapter We will learn about classes Garbage Collection Data Abstraction and encapsulation.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Software Development
CSC Data Structures, Fall, 2008 Monday, September 29, end of week 5, Generic Functions and Classes in C++
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Computer Science Projects Internal Assessment. Mastery Item Claimed Justification Where Listed Random Access File – Searching Lines P. 53 Random.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
Interfaces and Polymorphism CS 162 (Summer 2009).
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
CSCE , SPRING 2016 INSTRUCTOR: DR. NANCY M. AMATO 1.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
CSC 520 – Advanced Object Oriented Programming, Fall, 2010 Thursday, September 30 Week 5, Generics and Inheritance Techniques, Meyer Ch. 10 & 16.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
Object-Oriented Concepts
Sixth Lecture ArrayList Abstract Class and Interface
CS2006- Data Structures I Chapter 5 Linked Lists I.
Inheritance and Polymorphism
Agenda Warmup AP Exam Review: Litvin A2
Section 11.1 Class Variables and Methods
Chapter 6 Methods: A Deeper Look
Packages and Interfaces
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Object-Oriented Programming
Java Programming Language
CS2013 Lecture 7 John Hurley Cal State LA.
C++ Object Oriented 1.
Presentation transcript:

CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes

Interface Inheritance ~parson/JavaLang/sequence_adt An interface specifies operations as method signatures with no implementation bodies. A method signature consists of a method’s name, parameter types, return type and exceptions. An interface may also specific final constant values similar to class fields. All operations and constants are public. cp ~ parson/JavaLang/sequence_adt.zip ~/JavaLang/sequence_adt.zip cd ~/JavaLang ; unzip sequence_adt.zip ; cd sequence_adt gmake clean test

sequence_interface (ADT) – sequence of string objects cp ~parson/JavaLang/sequence_adt.zip ~/JavaLang/sequence_adt > sequence_interface.java sequence_interface insert(value : string, offset : integer) : boolean remove(offset : integer) : boolean get(offset : integer) : string size() : integer

Concrete class sequence_arrayimpl implements sequence_interface > sequence_interface sequence_arrayimpl insert(), remove() get(), size() private String [] array ; private int count ; // number of array elements actually used

Class sequence_linkedlistimpl implements sequence_interface > sequence_interface sequence_linkedlistimpl insert(), remove() get(), size() private static class listelement { // private local helper class String content ; // string stored at this element listelement next ; // next element, higher in number than this one } private listelement first ; private int count ; // number of linked list nodes actually used

Linked Lists contents next contents next contents next head tail There is a pointer variable or member data field, external to the list, that points to the head of the list. This pointer is null when the list is empty. The tail of the list has a null next pointer.

Tail recursive definitions of a List List := Node | Node List What problem results from this definition? What kind of List can you NOT represent? How might you fix this problem? Hint: Restate above as List := [Node] | [Node] + List List :=

Disadvantages of exposing implementation to client code Suppose you give client code direct access to the listelement linked list, so that any client pointer to a listelement is a sequence. How must you implement negative offsets and test non-negative offsets for validity? contents next contents next contents next start of a list start of a different list

Advantages of information hiding and data abstraction contents next contents next contents next start of the list (first), count of nodes Abstracting the sequence and hiding the linked list lets you use count to determine offset validity without searching the list. You can still provide client code with the advantages of recursive lists by creating operations to clone sub- sequences. Private operations can manipulate nodes directly.

Class sequence_arraylistimpl implements sequence_interface > sequence_interface sequence_arraylistimpl insert(), remove() get(), size() private ArrayList stringVector = new ArrayList ();

Modular design (object based design) Information hiding By hiding class implementation code and data structure from client code applications, and hiding client implementation details from class implementation code, it is possible to change them semi-independently. Encapsulation Basic language mechanisms include public, package, protected and private access control. Modularity – “plug and play” with compiled modules Reuse – library modules can be used in many apps

Object oriented design Interface inheritance A Java interface describes operations and constants of a set of Java classes without implementing any of those operations All methods and data are public. All data are final. There is no code for any of the methods. The interface specifies a contract. Operation preconditions state requirements on client code before a method call. Operation postconditions state the conditions met by the called method, if the preconditions have been met.

Concrete class sequence_arrayimpl implements sequence_interface > sequence_interface sequence_arrayimpl sequence_linkedlistimpl Polymorphism here means that one interface can take the form of multiple implementation classes.

Implementation Inheritance ~parson/JavaLang/sequence_aclass Fields and methods common to multiple peer classes go into a common base class. This base class is abstract if it cannot construct fully formed objects by itself. An abstract class requires one or more derived classes for construction. Base class methods may include protected helper methods.

Package sequence_aclass class sequence_abstract_baseclass > sequence_interface > sequence_abstract_baseclass size() : int protected int getRealOffset(int offset, boolean isinsert) : int (helper method to convert an offset parameter to a real offset) protected int count sequence_arrayimpl sequence_linkedlistimpl sequence_arraylistimpl