ICOM 4035 – Data Structures Lecture 2 – ADT and Interfaces Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.

Slides:



Advertisements
Similar presentations
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 8 – File Structures.
ICOM 4035 – Data Structures Lecture 15 – Graph ADT
ICOM 4035 – Data Structures Lecture 12 – Hashtables & Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico,
ICOM 4035 – Data Structures Lecture 8 – Doubly Linked Lists Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Maths for Computer Graphics
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Objects and Classes First Programming Concepts. 14/10/2004Lecture 1a: Introduction 2 Fundamental Concepts object class method parameter data type.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
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.
Pattern Abstract Factory
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
Dale Roberts Object Oriented Programming using Java - Class Constructors Dale Roberts, Lecturer Computer Science, IUPUI Department.
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
ICOM 4035 – Data Structures Lecture 9 – Stack ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Computer Science Standard Level Mastery Aspects. Mastery Item Claimed JustificationWhere Listed Arrays Used to store the student data Lines P.
ICOM 4035 – Data Structures Lecture 5 – List ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 4035 – Data Structures Lecture 6 – Big-O Notation Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 6 – September 6 th, 2001.
ICOM 4035 – Data Structures Lecture 13 – Trees ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Abstract Factory Design Pattern making abstract things.
Factory Method A Creational Design Pattern. Factory Method Key Features  Defines an interface for creating objects without needing to know each object’s.
Class Relationships Lecture Oo10 Dependencies. References n Booch, et al, The Unified Modeling Language User Guide, Chapt 5 p.69, Chapt 9 130, Chapt 10.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – Relational Model.
ICOM 4035 – Data Structures Lecture 14 – Binary Search Tree ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico,
ICOM 4035 – Data Structures Lecture 11 – Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 4035 – Data Structures Lecture 1 - Introduction Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 9 – September 18, 2001.
Encapsulation COMP 401, Fall 2014 Lecture 06 9/4/2014.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
ICOM 4035 – Data Structures Lecture 3 – Bag ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
ICOM 4035 – Data Structures Lecture 7 – Linked Lists Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez.
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
ICOM 4035 – Data Structures Lecture 10 – Queue ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 10 – September 20, 2001.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Matrix Operations.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com ICOM 5016 – Introduction.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 – August 23, 2001.
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.
CSC Programming for Science Lecture 28: Multi-dimensional Arrays.
Session 30 Final Review. Final Details Wednesday, December 14 at 8 AM Wright 5 (same classroom) Final will be comprehensive Open book Open notes Test.
Topic 2 Collections. 2-2 Objectives Define the concepts and terminology related to collections Discuss the abstract design of collections.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
David Evans CS201J: Engineering Software University of Virginia Computer Science Lecture 5: Implementing Data Abstractions.
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
Factory Patterns 1.
Software Design and Architecture
Object Oriented Programming using Java - Class Instance Variables
Interfaces.
Interfaces.
ICOM 5016 – Introduction to Database Systems
ICOM 5016 – Introduction to Database Systems
Math with Vectors I. Math Operations with Vectors.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

ICOM 4035 – Data Structures Lecture 2 – ADT and Interfaces Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel Rodriguez – All rights reserved

Lecture Organization Part I –Multiple implementations for ADT Part II – Using Interfaces to specify ADT Part III – Using Abstract Factories to create instances M. Rodriguez-MartinezICOM

Objectives Understand the proper use of interfaces to represent types for ADT – Just represent common operations Learn to hide values inside data structures that implement interfaces Provide motivating examples ICOM 4035M. Rodriguez-Martinez 3

Companion videos Lecture2 videos – Contain the coding process associated with this lecture – Shows how to build the interfaces, concrete classes, and factory classes mentioned here M. Rodriguez-MartinezICOM

Part I Multiple implementations for ADT M. Rodriguez-MartinezICOM

Vector ADT and Data Structure We created a Java class to represent a vector But this class only works for two dimensional vectors What if you need a 3D vector? What if you need a n- dimensional vector M. Rodriguez-MartinezICOM Fields x y Methods Vector Class x y (0,0) (a,b)

3D and Multidimensional vectors 3D vector – 3 coordinates – Vector3D class? Multidimensional vector – n coordinates – VectornD class? My program needs to know about specific vector class I use!  Can I do better? M. Rodriguez-MartinezICOM x y (0,0,0) (a,b,c) z 3D vector nD Vector

Part II Using Interfaces to specify ADT M. Rodriguez-MartinezICOM

Observations 2D, 3D, and nD Vectors all share common operations – Addition, magnitude, subtraction, inner product, scalar product Also, we need to – inspect the coordinates – convert to string They differ in terms of the number of coordinates they have M. Rodriguez-MartinezICOM

Better Organization via Interfaces Vector is an ADT but we made a straight mapping to a Java class – Your program in now tied to specific implementation  It is better to: – Map the ADT to a Java interface Specifies all operations – Build concrete classes that implement interface Provide storage for values You program code is written in terms of interfaces You instantiate any concrete class that you need and implements the interface – Use factory class for this purpose Result: cleaner, easier to maintain code M. Rodriguez-MartinezICOM

Vector Interface and its implementations Define a Java interface to represent Vector ADT Define concrete Java classes that implement Vector interface – They provide storage Example: – Vector2D– 2 coordinates – Vector3D – 3 coordinates – VectornD – array with n coordinates M. Rodriguez-MartinezICOM Vector2DVector3DVectornD > Vector

Possible Vector Concrete Classes M. Rodriguez-MartinezICOM Fields x y Methods Vector2D Class Fields x y Methods Vector3D Class 5 Fields elements dimensions Methods VectornD Class 0 z

Part III Using Abstract Factories to create instances M. Rodriguez-MartinezICOM

How to organize code and object creation We can use Abstract Factory pattern to control object creation Factory will return instances of Vector We tell the factory what type of vector we want and she gives us back an instance – Factory hides which concrete class is used for object creation Program is written based on the interfaces – Cannot be 100% but it works most of the time M. Rodriguez-MartinezICOM

Using Abstract Factory Pattern M. Rodriguez-MartinezICOM Concrete Class 1 Concrete Class 2 Concrete Class N > ADT Concrete Factory 1 Concrete Factory 2 Concrete Factory N > ADT Factory > Product

Using Abstract Factory Pattern M. Rodriguez-MartinezICOM Vector2DVector3DVectornD > Vector Vector2D Factory Vector3D Factory VectornD Factory > VectorFactory > Product

Benefits You can have as many vector implementations as you need Main program might not be changed if – Your factory class reads configuration from command line or properties file Ex. Tell it what vector to use with string: “vector2d” Your code is based on the Vector interface – Only one concept to deal with M. Rodriguez-MartinezICOM

Questions? – ICOM 4035M. Rodriguez-Martinez 18