CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Linked Lists Chapter 4.
DATA STRUCTURES USING C++ Chapter 5
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
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:
Object Orientation Chapter SixteenModern Programming Languages, 2nd ed.1 Spring 2012.
Object Orientation Chapter SixteenModern Programming Languages, 2nd ed.1.
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.
Software Engineering and Design Principles Chapter 1.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Cmp Sci 187: Midterm Review Based on Lecture Notes.
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.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
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.
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.
Designing Classes Prelude © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Data Abstaraction Chapter 10.
CSC Data Structures, Fall, 2008 Monday, September 29, end of week 5, Generic Functions and Classes in C++
Chapter 10, Slide 1 ABSTRACT DATA TYPES Based on the fundamental concept of ABSTRACTION:  process abstraction  data abstraction Both provide:  information.
Views of Data Data – nouns of programming world the objects that are manipulated information that is processed Humans like to group information Classes,
Computer Science Projects Internal Assessment. Mastery Item Claimed Justification Where Listed Random Access File – Searching Lines P. 53 Random.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
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.
© 2006 Pearson Addison-Wesley. All rights reserved5 B-1 Chapter 5 (continued) Linked Lists.
Lecture Objectives  To understand how Java implements a stack  To learn how to implement a stack using an underlying array or linked list  Implement.
Interfaces and Polymorphism CS 162 (Summer 2009).
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
CS 116 Lecture 1 John Korah Contains content provided by George Koutsogiannakis & Matt Bauer.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
1 Linked Lists Chapter 3. 2 Objectives You will be able to: Describe an abstract data type for lists. Understand and use an implementation of a List ADT.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
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.
1 CS162: Introduction to Computer Science II Abstract Data Types.
Object-Oriented Concepts
Sixth Lecture ArrayList Abstract Class and Interface
CS2006- Data Structures I Chapter 5 Linked Lists I.
Building Java Programs
Inheritance and Polymorphism
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
Object-Oriented Programming Using C++
Building Java Programs
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Dynamic Data Structures and Generics
Object-Oriented Programming
CIS 199 Final Review.
Java Programming Language
CS2013 Lecture 7 John Hurley Cal State LA.
Building Java Programs
Lecture 7: Linked List Basics reading: 16.2
C++ Object Oriented 1.
Lecture 4 – Data collection List ADT
Presentation transcript:

CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes

sequence_interface (ADT) – sequence of string objects cp ~parson/JavaLang/sequence_adt ~/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.

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