Adapter Pattern Context:

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Jan Java I/O Yangjun Chen Dept. Business Computing University of Winnipeg.
Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Lecture 15: I/O and Parsing
Exceptions. Definition Exception: something unexpected that can occur in the execution of a program e.g., divide by zero or attempt to open a file that.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
File Input and Output Recitation 04/03/2009 CS 180 Department of Computer Science, Purdue University.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
1 Introduction to Console Input  Primitive Type Wrapper Classes  Converting Strings to Numbers  System.in Stream  Wrapping System.in in a Buffered.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Java Programming: I/O1 Java I/O Reference: java.sun.com/docs/books/tutorial/essential/io/
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
Two Ways to Store Data in a File Text format Binary format.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Java I18n and Unicode JaxJug lightning talk 4/15/09.
Computer Science 209 Introduction to Design Patterns: Iterator Composite Decorator.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Program data (instance variables, local variables, and parameters) is transient, because its lifetime ends with the program...if not, before. Sometimes.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
JAVA I/O © EnhanceEdu, IIIT Hyderabad. Contents 3/29/2010EnhanceEdu, IIIT - H 2  Command Line I/O  File Class  Streams  Byte Streams [Low level and.
I/O in Java Dennis Burford
Data Persistence Nasrullah Niazi. Share Preferences The SharedPreferences class provides a general framework that allows you to save and retrieve persistent.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
Input/output Input in java is stream based.A stream represents sequence of bytes or characters. Stream provides an abstract view of I/O. Stream can be.
Two Ways to Store Data in a File  Text format  Binary format.
More Design Patterns Horstmann ch.10.1,10.4. Design patterns Structural design patterns –Adapter –Composite –Decorator –Proxy Behavioral design patterns.
© Amir Kirsh Files and Streams in Java Written by Amir Kirsh.
1 Software 1 Java I/O. 2 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating.
Read and Write Files  By the end of this lab you will be able to:  Write a file in internal storage  Read a file from internal storage  Write a file.
Computer Science 209 The Adapter Pattern. The Context of the Adapter Pattern I want to use an existing class (the adaptee) without modifying it The context.
Streams & Files. Java I/O Classes Saving data to / Loading data from files Two Choices: Binary-Formatted or Text-Formatted Data – int x = 1234; – Binary.
– Advanced Programming P ROGRAMMING IN Lecture 22 Input and Output System.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Decorator Design Pattern Rick Mercer CSC 335: Object-Oriented Programming and Design.
I/O Basics Java does provide strong, flexible support for I/O related to files and networks. Java’s console based interaction is limited since in real.
Java Input/Output. Java Input/output Input is any information that is needed by your program to complete its execution. Output is any information that.
Duke CPS Problem: reading, reading efficiently: C++ and Java l Many C++ stream implementations are slow, sometimes reading a file needs to be.
CSI 3125, Preliminaries, page 1 Files. CSI 3125, Preliminaries, page 2 Reading and Writing Files Java provides a number of classes and methods that allow.
Simple Java I/O Part I General Principles. Streams All modern I/O is stream-based A stream is a connection to a source of data or to a destination for.
Java Input / Output l a modular approach to input/output: - different stream objects are connected/wrapped to handle I/O l a data stream object: a flow.
Java Programming: Advanced Topics 1 Input/Output and Serialization.
Recitation File I/O. File I/O File inFile = new File("data.txt"); File inFile = new File (“/Users/sunil/test.txt");
java.io supports console and file I/O
The Java IO System Different kinds of IO Different kinds of operations
CSC1351 Class 6 Classes & Inheritance.
Keerthi Nelaturu Url: site.uottawa.ca/~knela006
CSG2H3 Object Oriented Programming
Streams, File I/O and Scanner class
OO Design and Programming II I/O: Reading and Writing
I/O Basics.
File.
Java’s Hierarchy Input/Output Classes and Their Purpose
JAVA IO.
إستراتيجيات ونماذج التقويم
Text File Read and Write Method
Computer Science 209 The Adapter Pattern.
Web Design & Development Lecture 8
Java Input/Output (I/O)
CS 240 – Advanced Programming Concepts
Streams and Readers The stream hierarchy is for reading bytes, the reader/writer hierarchy is for reading characters Unicode characters can be used internationally,
David Davenport Spring 2005
Presentation transcript:

Adapter Pattern Context: 08/15/09 Adapter Pattern Context: You want to change the interface of an existing class (the adaptee) to a different interface. Forces: You want to be able to use a variety of objects to provide some functionality, without changing the application. But, the objects have different interfaces.

Readers as Adapters InputStream reads input as bytes. 08/15/09 Readers as Adapters InputStream reads input as bytes. int b = inputStream.read( ); InputStreamReader interprets the input as characters. InputStreamReader reader = new InputStreamReader( inputStream ); char c = (char) reader.read( ); BufferedReader groups the characters into lines BufferedReader bufReader = new BufferedReader( reader ); String line = bufReader.readLine( );

Adapter wraps a component 08/15/09 Adapter wraps a component IInputStream instream = new FileInputStream( "filename" ); InputStreamReader reader = new InputStreamReader( instream ); BufferedReader bufReader = new BufferedReader( reader ); String line = bufReader.readLine( ); BufferedReader (reads strings) InputStreamReader (read chars) InputStream (reads bytes)

08/15/09 "Adapters" in Swing A MouseListener (interface) requires you to implement 5 methods. If you only want to use 1 method, you must write 4 empty methods.