Decorator Pattern. CS356 Object-Oriented Design and Programming November 7, 2014
|
|
- Pierce Stephens
- 5 years ago
- Views:
Transcription
1 Decorator Pattern CS356 Object-Oriented Design and Programming November 7, 2014 Yu Sun, Ph.D.
2 Decorator Intent Dynamically attach additional responsibilities to an object Provide a flexible alternative to subclassing (static) Decorating object is transparent to the core component Also Known As Wrapper
3 Motivation We want to add different kinds of borders and/or scrollbars to a TextView GUI component Borders Plain, 3D, or Fancy Scrollbars Horizontal and/or Vertical
4 Motivation An inheritance solution requires 15 subclasses to represent each type of view 1. TextView-Plain 2. TextView-3D 3. TextView-Fancy 4. TextView-Horizontal 5. TextView-Vertical 6. TextView-Horizontal-Vertical 7. TextView-Plain-Horizontal 8. TextView-Plain-Vertical 9. TextView-Plain-Horizontal-Vertical 10. TextView-3D-Horizontal 11. TextView-3D-Vertical 12. TextView-3D-Horizontal-Vertical 13. TextView-Fancy-Horizontal 14. TextView-Fancy-Vertical 15. TextView-Fancy-Horizontal-Vertical
5 Solution 1: Use Object Composition TextView border scrollbar Border Scrollbar PlainBorder 3DBorder FancyBorder Horizontal Scrollbar Vertical Scrollbar Horizontal Vertical Scrollbar Is it Open-Closed? Can you add new features without affecting TextView? e.g., what about adding sound to a TextView?
6 Decorator Pattern Solution VisualComponent TextView VisualDecorator component Border Scrollbar PlainBorder 3DBorder FancyBorder Change the Skin, not the Guts! Horizontal Scrollbar TextView has no borders or scrollbars! Vertical Scrollbar Horizontal Vertical Scrollbar Add borders and scrollbars on top of a TextView
7 Structure What is significance of this? Component ConcreteComponent Decorator component Component->; ConcreteDecoratorA addedstate ConcreteDecoratorB AddedBehavior() Decorator::; AddBehavior(); The decorator forwards requests to the component and may perform additional actions (such as drawing a border) before or after any forwarding
8 Component u Defines the interface for objects that can have responsibilities added dynamically Component ConcreteComponent Decorator component Component->; ConcreteDecoratorA addedstate ConcreteDecoratorB AddedBehavior() Decorator::; AddBehavior();
9 ConcreteComponent u The "base" object to which additional responsibilities can be added Component ConcreteComponent Decorator component Component->; ConcreteDecoratorA addedstate ConcreteDecoratorB AddedBehavior() Decorator::; AddBehavior();
10 Decorator u Maintains a reference to a Component object u Defines an interface conformant to Component's interface Component ConcreteComponent Decorator component Component->; ConcreteDecoratorA addedstate ConcreteDecoratorB AddedBehavior() Decorator::; AddBehavior();
11 ConcreteDecorator u Adds responsibilities to the component Component ConcreteComponent Decorator component Component->; ConcreteDecoratorA addedstate ConcreteDecoratorB AddedBehavior() Decorator::; AddBehavior();
12 Decorator Applicability Dynamically and transparently attach responsibilities to objects Responsibilities that can be withdrawn Extension by subclassing is impractical May lead to too many subclasses
13 Example Sales Ticket Printing
14 Example: Decorate Sales Ticket Printing Assume the SalesTicket currently creates an html sales receipt for an Airline Ticket New Requirements Add header with company name Add footer that is an advertisement During the holidays add holiday relevant header(s) and footer(s) We re not sure how many such things One solution Place control in SalesTicket Then you need flags to control what header(s) get printed
15 Decorator Approach A layered approach Start chain with decorators End with original object Decorator 1 Decorator 2 Concrete Component
16 Example Sales Ticket Printing Component SalesOrder main(string[]) SalesTicket component TicketDecorator TicketDecorator(Component) Configuration getsalesticket() HeaderDecorator1 HeaderDecorator1(Component) printheader() FooterDecorator1 FooterDecorator1(Component) printfooter() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
17 A SalesTicket Implementation Component SalesOrder main(string[]) SalesTicket HeaderDecorator1 HeaderDecorator1(Component) printheader() // Instances TicketDecorator of this class are the sales tickets // that may be decorated TicketDecorator(Component) Configuration public class SalesTicket extends Component { getsalesticket() public component void { // Hard coded here, but simpler than // adding a new Customer class now System.out.println("Customer: Bob"); FooterDecorator1 System.out.println("The sales ticket itself"); System.out.println("Total: FooterDecorator1(Component) $123.45"); printfooter() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
18 TicketDecorator Component SalesOrder main(string[]) SalesTicket HeaderDecorator1 HeaderDecorator1(Component) printheader() TicketDecorator TicketDecorator(Component) Configuration getsalesticket() component public abstract class TicketDecorator extends Component { private Component component; FooterDecorator1 public TicketDecorator(Component FooterDecorator1(Component) c) { component = c; printfooter() HeaderDecorator2 public void FooterDecorator2 { if(component!= null) HeaderDecorator2(Component) FooterDecorator2(Component) component.; printheader() printfooter()
19 A Header Decorator Component public class HeaderDecorator1 extends TicketDecorator { SalesOrder public HeaderDecorator1(Component c) { super(c); main(string[]) SalesTicket TicketDecorator public void { this.printheader(); TicketDecorator(Component) super.; component Configuration getsalesticket() HeaderDecorator1 HeaderDecorator1(Component) printheader() public void printheader() { System.out.println("@@ Header FooterDecorator1 FooterDecorator1(Component) printfooter() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
20 Example Sales Ticket Printing Component public class FooterDecorator2 extends TicketDecorator { public FooterDecorator2(Component c) { super(c); SalesTicket TicketDecorator public void { super.; this.printfooter(); TicketDecorator(Component) component SalesOrder main(string[]) Configuration getsalesticket() public void printfooter() { System.out.println("## FOOTER HeaderDecorator1 FooterDecorator1 Two ##"); HeaderDecorator1(Component) FooterDecorator1(Component) printheader() printfooter() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
21 SalesOrder (Client) Component public class SalesOrder { public static void main(string[] args) { SalesOrder SalesTicket s = new SalesOrder(); TicketDecorator s.; TicketDecorator(Component) public void component { // Get an object decorated dynamically Component myst = Configuration.getSalesTicket(); myst.; HeaderDecorator1 FooterDecorator1 HeaderDecorator1(Component) // calcsalestax... printheader() FooterDecorator1(Component) printfooter() SalesOrder main(string[]) Configuration getsalesticket() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
22 Example Configuration Component // This object will determine how to decorate the // SalesTicket. This could become a Factory public class Configuration { public static Component getsalesticket() { // SalesTicket Return a decorated SalesTicket TicketDecorator return TicketDecorator(Component) new HeaderDecorator1( new HeaderDecorator2( new FooterDecorator1( component new FooterDecorator2( new SalesTicket() )))); HeaderDecorator1 FooterDecorator1 HeaderDecorator1(Component) printheader() FooterDecorator1(Component) printfooter() SalesOrder main(string[]) Configuration getsalesticket() HeaderDecorator2 HeaderDecorator2(Component) printheader() FooterDecorator2 FooterDecorator2(Component) printfooter()
23 Output with Current Configuration Output: Header One >> Header Two << Customer: Bob The sales ticket itself Total: $ %% FOOTER One %% ## FOOTER Two ##
24 Implementation Issues Keep Decorators lightweight Don't put data members in Component Use it for shaping the interface Omitting the abstract Decorator class If only one decoration is needed Subclasses may pay for what they don't need
25 Return to TextView Example The TextView class knows nothing about Borders and Scrollbars VisualComponent public class TextView { TextView public void draw() { VisualDecorator // Code to draw this Text object component Border public void resize () { // Code to resize this Text object Scrollbar PlainBorder 3DBorder FancyBorder Horizontal Scrollbar Vertical Scrollbar Horizontal Vertical Scrollbar
26 A New Class The new ImageView class knows nothing about Borders and Scrollbars public class ImageView { public void draw() { // Code to draw this Image Object public void resize () { // Code to resize this Image Object
27 Decorators Contain Components The decorators don t need to know about components public class FancyBorder extends Border { VisualComponent public FancyBorder(VisualComponent c) { super(c); TextView public VisualDecorator void draw() { // forward draw message component component.draw(); Border // Code to draw this FancyBorder object Scrollbar PlainBorder 3DBorder FancyBorder Horizontal Scrollbar Vertical Scrollbar Horizontal Vertical Scrollbar
28 How to Use Decorators public class Client { public static void main(string[] args) { TextView data = new TextView(); Component borderdata = new FancyBorder(data); Component scrolleddata = new VertScrollbar(data); Component borderandscrolleddata = new HorzScrollbar(borderData);
29 Decorator Pattern in Java
30 Decorator Pattern in Java public class JavaIO { public static void main(string[] args) { // Open an InputStream. FileInputStream in = new FileInputStream("test.dat"); // Create a buffered InputStream. BufferedInputStream bin = new BufferedInputStream(in); // Create a buffered, data InputStream. DataInputStream dbin = new DataInputStream(bin); // Create a buffered, pushback, data InputStream. PushbackInputStream pbdbin = new PushbackInputStream(dbin); BufferedReader keyboard = new BufferedReader( new InputStreamReader(System.in));
31 Java Streams With > 60 streams in Java, you can create a wide variety of input and output streams This provides flexibility (good) It also adds complexity (bad) Flexibility made possible with inheritance and classes that accept many different classes that extend the parameter You can have an InputStream instance or any instance of a class that extends InputStream public InputStreamReader(InputStream in)
32 Consequences Ë Transparency very good Ë More flexibility than static inheritance Allows to mix and match responsibilities Allows to apply a property twice Ë Avoid feature-laden classes high-up in the hierarchy Pay-as-you-go approach Easy to define new types of decorations Ò A decorator and its component aren't identical Ò Lots of little objects Easy to customize, but hard to learn and debug
The Decorator Pattern. Design Patterns In Java Bob Tarr
The Decorator Pattern Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Also Known As Wrapper Motivation
More informationDesign Patterns. Decorator Pattern. Ekim 2017
Design Patterns Decorator Pattern ebru@hacettepe.edu.tr ebruakcapinarsezer@gmail.com http://yunus.hacettepe.edu.tr/~ebru/ @ebru176 Ekim 2017 Let s try to design Each football player has the abilities of
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Decorator 1 2 3 4 Decorator Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing
More informationSoftware Quality Management
2004-2005 Marco Scotto (Marco.Scotto@unibz.it) Outline Structural Patterns Adapter Composite Decorator 2 Design Pattern Space Purpose Creational Structural Behavioral Scope Class Factory Method Adapter
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Decorator 1 An example 2 Your first idea of implementation 3 In reality 4 Now a beverage can be mixed from different condiment to form a new beverage 5 6
More informationTecniche di Progettazione: Design Patterns
Tecniche di Progettazione: Design Patterns GoF: Decorator 1 Decorator Intent Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending
More informationDesign Patterns B. Reid Holmes. Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book
Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns B Reid Holmes Lecture 15 - Thursday November 10 2011. GoF design patterns $ %!!!! $ "!
More informationDesign Patterns IV Structural Design Patterns, 1
Structural Design Patterns, 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 Class Object Department of Computer Science The Australian National University 18.1 1 2 Class Object
More informationSoftware Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt
Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Winter Semester 16/17 Decorator Pattern Intent of the Decorator Pattern We need
More informationSoftware Engineering Design & Construction
Winter Semester 16/17 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt Decorator Pattern Intent of the Decorator Pattern We need
More informationCOSC 3351 Software Design. Design Patterns Structural Patterns (I)
COSC 3351 Software Design Design Patterns Structural Patterns (I) Spring 2008 Purpose Creational Structural Behavioral Scope Class Factory Method Adaptor(class) Interpreter Template Method Object Abstract
More informationDesign Patterns IV. Alexei Khorev. 1 Structural Patterns. Structural Patterns. 2 Adapter Design Patterns IV. Alexei Khorev. Structural Patterns
Structural Design Patterns, 1 1 COMP2110/2510 Software Design Software Design for SE September 17, 2008 2 3 Department of Computer Science The Australian National University 4 18.1 18.2 GoF Structural
More informationLast Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005
1 Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/6448 - Spring Semester, 2005 2 Last Lecture Design Patterns Background and Core Concepts Examples
More informationLast Lecture. Lecture 26: Design Patterns (part 2) State. Goals of Lecture. Design Patterns
Lecture 26: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Last Lecture Design Patterns Background and Core Concepts Examples Singleton,
More informationDesign Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester
Design Patterns Comp2110 Software Design Department of Computer Science Australian National University Second Semester 2005 1 Design Pattern Space Creational patterns Deal with initializing and configuring
More informationChain of Responsibility
Chain of Responsibility CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 17, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Chain of Responsibility Intent Decouple sender
More informationI/O streams. Byte Streams Character Streams InputStream ByteArrayInputStream FileInputStream FilterInputStream
Course Name: Advanced Java Lecture 9 Topics to be covered I/O streams Byte Streams Character Streams InputStream ByteArrayInputStream FileInputStream FilterInputStream Introduction A Stream is a sequence
More informationDesign Patterns in C++
Design Patterns in C++ Structural Patterns Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa March 23, 2011 G. Lipari (Scuola Superiore Sant Anna) Structural patterns March
More informationGoals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming
Goals of Lecture Lecture 27: OO Design Patterns Cover OO Design Patterns Background Examples Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2001 April 24, 2001 Kenneth
More informationSpecial error return Constructors do not have a return value What if method uses the full range of the return type?
23 Error Handling Exit program (System.exit()) usually a bad idea Output an error message does not help to recover from the error Special error return Constructors do not have a return value What if method
More informationSOFTWARE PATTERNS. Joseph Bonello
SOFTWARE PATTERNS Joseph Bonello MOTIVATION Building software using new frameworks is more complex And expensive There are many methodologies and frameworks to help developers build enterprise application
More informationDesign Patterns Reid Holmes
Material and some slide content from: - Head First Design Patterns Book - GoF Design Patterns Book Design Patterns Reid Holmes GoF design patterns $ %!!!! $ "! # & Pattern vocabulary Shared vocabulary
More informationThe Java I/O System. Binary I/O streams (ASCII, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
The Java I/O System Binary I/O streams (ASCII, 8 bits) InputStream OutputStream The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing binary I/O to character I/O
More informationAdapter Pattern Structural
Adapter Pattern Structural Intent» Convert the interface of a class into a different interface that a client expects.» Lets classes work together that otherwise could not Adapter-1 Class Adapter Motivation
More informationFile IO. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 20
File IO Computer Science and Engineering College of Engineering The Ohio State University Lecture 20 I/O Package Overview Package java.io Core concept: streams Ordered sequences of data that have a source
More informationFiles and Streams
Files and Streams 4-18-2006 1 Opening Discussion Do you have any questions about the quiz? What did we talk about last class? Do you have any questions about the assignment? What are files and why are
More informationChapter 10. IO Streams
Chapter 10 IO Streams Java I/O The Basics Java I/O is based around the concept of a stream Ordered sequence of information (bytes) coming from a source, or going to a sink Simplest stream reads/writes
More informationObject-Oriented Oriented Programming Adapter Pattern. CSIE Department, NTUT Woei-Kae Chen
Object-Oriented Oriented Programming Adapter Pattern CSIE Department, NTUT Woei-Kae Chen Adapter: Intent Convert the interface of a class into another interface clients expect. Adapter lets classes work
More informationCS 520/620 Advanced Software Engineering Spring February 02, 2016
CS 520/620 Advanced Software Engineering Spring 2016 February 02, 2016 Logistics Project proposals Elevator pitches on Thursday Deadline for creating groups: 02/03/2016, 11:55pm Deadline for submitting
More informationADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya
ADAPTER Presented By: Mallampati Bhava Chaitanya Topics Intent Motivation Applicability Structure Participants & Collaborations Consequences Sample Code Known Uses Related Patterns Intent Convert the interface
More informationSoftwaretechnik. Design Patterns. Matthias Keil. Albert-Ludwigs-Universität Freiburg
Softwaretechnik Design Patterns Matthias Keil Institute for Computer Science Faculty of Engineering University of Freiburg 14. Juni 2012 Design Patterns (1) solutions for specific problems in object-oriented
More informationOODP Session 5a. Web Page: Visiting Hours: Tuesday 17:00 to 19:00
OODP Session 5a Next week: Reading week Session times PT group 1 Monday 18:00 21:00 room: Malet 403 PT group 2 Thursday 18:00 21:00 room: Malet 407 FT Tuesday 13:30 17:00 room: Malet 404 Email: oded@dcs.bbk.ac.uk
More informationObject-Oriented Oriented Programming Adapter Pattern
Object-Oriented Oriented Programming Pattern CSIE Department, NTUT Woei-Kae Chen : Intent Convert the interface of a class into another interface clients expect. lets classes work together that could not
More informationPrinciples of Software Construction: Objects, Design, and Concurrency. Assigning Responsibilities to Objects. toad. Jonathan Aldrich Charlie Garrod
Principles of Software Construction: Objects, Design, and Concurrency Assigning Responsibilities to Objects toad Fall 2014 Jonathan Aldrich Charlie Garrod School of Computer Science Key concepts from Thursday
More informationSoftwaretechnik. Design Patterns. Stephan Arlt SS University of Freiburg. Stephan Arlt (University of Freiburg) Softwaretechnik SS / 47
Softwaretechnik Design Patterns Stephan Arlt University of Freiburg SS 2011 Stephan Arlt (University of Freiburg) Softwaretechnik SS 2011 1 / 47 Design Patterns Gamma, Helm, Johnson, Vlissides: Design
More informationDecorator. The Decorator pattern gives a mechanism without using inheritance.
Sometimes we need a way to add responsibilities to an object dynamically and transparently. The Decorator pattern gives a mechanism without using inheritance. The Decorator pattern allows one to add and
More informationByte and Character Streams. Reading and Writing Console input and output
Byte and Character Streams Reading and Writing Console input and output 1 I/O basics The io package supports Java s basic I/O (input/output) Java does provide strong, flexible support for I/O as it relates
More information1.00 Lecture 30. Sending information to a Java program
1.00 Lecture 30 Input/Output Introduction to Streams Reading for next time: Big Java 15.5-15.7 Sending information to a Java program So far: use a GUI limited to specific interaction with user sometimes
More informationCS 2340 Objects and Design
CS 2340 Objects and Design Structural Patterns Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design Structural Patterns 1 / 10 Structural Design Patterns
More informationLecture 13: Design Patterns
1 Lecture 13: Design Patterns Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2005 2 Pattern Resources Pattern Languages of Programming Technical conference on Patterns
More informationOutline. Design Patterns, cont. Wrappers. Adapter Pattern. Based on material by Michael Ernst, University of Washington
Outline Design Patterns, cont. Based on material by Michael Ernst, University of Washington Design patterns Creational patterns, recap Subtypes: Factory method, Factory object, Prototype Sharing: Singleton
More informationVisitor Pattern CS356 Object-Oriented Design and Programming November 5, 2014 Yu Sun, Ph.D.
Visitor Pattern CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 5, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Visitor Intent Represent an operation on elements of
More informationPattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository
Pattern Resources Lecture 25: Design Patterns Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2003 Pattern Languages of Programming Technical conference on Patterns
More informationCOMP 213. Advanced Object-oriented Programming. Lecture 19. Input/Output
COMP 213 Advanced Object-oriented Programming Lecture 19 Input/Output Input and Output A program that read no input and produced no output would be a very uninteresting and useless thing. Forms of input/output
More informationJava Input/Output. 11 April 2013 OSU CSE 1
Java Input/Output 11 April 2013 OSU CSE 1 Overview The Java I/O (Input/Output) package java.io contains a group of interfaces and classes similar to the OSU CSE components SimpleReader and SimpleWriter
More informationDesign Patterns. Produced by. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology
Design Patterns Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Template Method Design
More informationLecture 11.1 I/O Streams
21/04/2014 Ebtsam AbdelHakam 1 OBJECT ORIENTED PROGRAMMING Lecture 11.1 I/O Streams 21/04/2014 Ebtsam AbdelHakam 2 Outline I/O Basics Streams Reading characters and string 21/04/2014 Ebtsam AbdelHakam
More informationExceptions and Working with Files
Exceptions and Working with Files Creating your own Exceptions. You have a Party class that creates parties. It contains two fields, the name of the host and the number of guests. But you don t want to
More informationSoftware 1 with Java. Recitation No. 7 (Java IO) May 29,
Software 1 with Java Recitation No. 7 (Java IO) May 29, 2007 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes
More informationSoftware 1 with Java. Recitation No. 9 (Java IO) December 10,
Software 1 with Java Recitation No. 9 (Java IO) December 10, 2006 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files
More informationObject-Oriented Programming Design. Topic : Streams and Files
Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams
More informationLecture 8. Object Oriented Design
Lecture 8 Object Oriented Design The Challenge of Making Software Did a lot of JMan for you Classes already completed Detailed specifications Lengthy instructions You just fill in blanks The Real World
More informationComponent ConcreateComponent Decorator ConcreateDecoratorA ConcreteDecoratorB
Comp435 Object-Oriented Design Week 12 Computer Science PSU HBG Attach additional responsibilities to an object dynamically Provide a flexible alternative to subclassing for extending functionality Attach
More informationCS Week 14 Page 1
CS 201 -- Week 14 Accelerated Intro to Computer Science (Java) Reading: 1. Deitel & Deitel, Chapters 10, 14 Objectives: 1. Continue discussing Object Oriented Programming 2. Learn more about Files and
More informationFull file at Chapter 2 - Inheritance and Exception Handling
Chapter 2 - Inheritance and Exception Handling TRUE/FALSE 1. The superclass inherits all its properties from the subclass. ANS: F PTS: 1 REF: 76 2. Private members of a superclass can be accessed by a
More informationSoftware Engineering
Software Engineering Structural Design Patterns Software Engineering 2012-2013 Based on slides of: Mira Balaban Department of Computer Science Ben-Gurion university F. Tip. IBM T J Watson Research Center.
More informationJava Input / Output. CSE 413, Autumn 2002 Programming Languages.
Java Input / Output CSE 413, Autumn 2002 Programming Languages http://www.cs.washington.edu/education/courses/413/02au/ 18-November-2002 cse413-18-javaio 2002 University of Washington 1 Reading Readings
More informationAdapter & Facade. CS356 Object-Oriented Design and Programming November 19, 2014
Adapter & Facade CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 19, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu Adapter Problem Have an object with an interface
More informationcopy.dept_change( CSE ); // Original Objects also changed
UNIT - III Topics Covered The Object class Reflection Interfaces Object cloning Inner classes Proxies I/O Streams Graphics programming Frame Components Working with 2D shapes. Object Clone Object Cloning
More informationObjec&ves. Review. Standard Error Streams
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 Review What are benefits of excep&ons What principle of Java do files break if we re not careful? What class
More information09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.
CSE 143 Java Streams Reading: 19.1, Appendix A.2 GREAT IDEAS IN COMPUTER SCIENCE REPRESENTATION VS. RENDERING 4/28/2002 (c) University of Washington 09-1 4/28/2002 (c) University of Washington 09-2 Topics
More informationCore Java Contents. Duration: 25 Hours (1 Month)
Duration: 25 Hours (1 Month) Core Java Contents Java Introduction Java Versions Java Features Downloading and Installing Java Setup Java Environment Developing a Java Application at command prompt Java
More informationThe Composite Pattern
The Composite Pattern Intent Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. This is called
More informationFoundations of object orientation
Foreword Preface List of projects discussed in detail in this book Acknowledgments Part 1 Chapter 1 Chapter 2 Foundations of object orientation Objects and classes 1.1 Objects and classes 1.2 Creating
More informationResearch Article A Design Pattern Approach to Improve the Structure and Implementation of the Decorator Design Pattern
Research Journal of Applied Sciences, Engineering and Technology 13(5): 416-421, 2016 DOI:10.19026/rjaset.13.2961 ISSN: 2040-7459; e-issn: 2040-7467 2016 Maxwell Scientific Publication Corp. Submitted:
More informationDarshan Institute of Engineering & Technology for Diploma Studies
Streams A stream is a sequence of data. In Java a stream is composed of bytes. In java, 3 streams are created for us automatically. 1. System.out : standard output stream 2. System.in : standard input
More informationCS 11 java track: lecture 3
CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces
More informationDesign Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester
Design Patterns Comp2110 Software Design Department of Computer Science Australian National University Second Semester 2006 1 What is a Design Pattern? Current use comes from the work of the architect
More informationSoftware 1. Java I/O
Software 1 Java I/O 1 The java.io package The java.io package provides: Classes for reading input Classes for writing output Classes for manipulating files Classes for serializing objects 2 Streams A stream
More informationDesign Patterns - Decorator Pattern
Design Patterns - Decorator Pattern Decorator pattern allows a user to add new functionality to an existing object without altering its structure. This type of design pattern comes under structural pattern
More informationDesign Patterns Revisited
CSC 7322 : Object Oriented Development J Paul Gibson, A207 paul.gibson@int-edu.eu http://www-public.it-sudparis.eu/~gibson/teaching/csc7322/ Design Patterns Revisited /~gibson/teaching/csc7322/l13-designpatterns-2.pdf
More information1.0 Libraries Technical Overview
1.0 Libraries Technical Overview Jonni Kanerva Frank Yellin JavaSoft Outline Introduction Functionality in the 1.0 Libraries Distributed design of the Java platform Instructive oddities Design patterns
More informationDesign Patterns (DP) In the beginning. It s not a course about DP (just a little) A lot of good design and efficient implementation is based on DP
User Interface Design 2 Design Patterns IT Uppsala University Design Patterns (DP) It s not a course about DP (just a little) A lot of good design and efficient implementation is based on DP In order to
More informationWeek 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O
Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file
More informationWeb Server Project. Tom Kelliher, CS points, due May 4, 2011
Web Server Project Tom Kelliher, CS 325 100 points, due May 4, 2011 Introduction (From Kurose & Ross, 4th ed.) In this project you will develop a Web server in two steps. In the end, you will have built
More informationLOG6306 : Études empiriques sur les patrons logiciels
LOG6306 : Études empiriques sur les patrons logiciels Foutse Khomh The Abstract Factory DP This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 3.0 Unported License Context
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationPerforming input and output operations using a Byte Stream
Performing input and output operations using a Byte Stream public interface DataInput The DataInput interface provides for reading bytes from a binary stream and reconstructing from them data in any of
More informationCSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich
CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and
More informationYour Final Bow. They would like to be able to combine tests, such as count all the 5-letter words that start with t.
Your Final Bow Last week, we learned about the Strategy pattern as a way to implement a Play class that can count the words in its text that satisfy an arbitrary test. The test is passed as an argument
More informationLecture 4: Exceptions. I/O
Lecture 4: Exceptions. I/O Outline Access control. Class scope Exceptions I/O public class Malicious { public static void main(string[] args) { maliciousmethod(new CreditCard()); } static void maliciousmethod(creditcard
More informationCourse Content. Objectives of Lecture 22 File Input/Output. Outline of Lecture 22. CMPUT 102: File Input/Output Dr. Osmar R.
Structural Programming and Data Structures Winter 2000 CMPUT 102: Input/Output Dr. Osmar R. Zaïane Course Content Introduction Objects Methods Tracing Programs Object State Sharing resources Selection
More informationUsing Design Patterns in Java Application Development
Using Design Patterns in Java Application Development ExxonMobil Research & Engineering Co. Clinton, New Jersey Michael P. Redlich (908) 730-3416 michael.p.redlich@exxonmobil.com About Myself Degree B.S.
More informationProject #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.
Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple magazine data system. Milestones:
More informationInterlude. Object Oriented Design
Interlude Object Oriented Design Announcements for This Lecture This Week Today is an Interlude Nothing today is on exam Another Big Picture talk Relevant to Assignment 6 Review for exam posted New Review
More informationObjec&ves STANDARD ERROR. Standard Error Streams. Ø Byte Streams Ø Text Streams 10/5/16. Oct 5, 2016 Sprenkle - CSCI209 1
Objec&ves Standard Error Streams Ø Byte Streams Ø Text Streams Oct 5, 2016 Sprenkle - CSCI209 1 STANDARD ERROR Oct 5, 2016 Sprenkle - CSCI209 2 1 Standard Streams Preconnected streams Ø Standard Out: stdout
More informationDesign Aspects of the Standard I/O Library. Design with Java:
Design Aspects of the Standard I/O Library Design with Java: QUOIN 1208 Massachusetts Avenue, Suite 3 Cambridge, Massachusetts 02138 tel: 617.492.6461 fax: 617.492.6461 email: info@quoininc.com web: www.quoininc.com
More informationInput from Files. Buffered Reader
Input from Files Buffered Reader Input from files is always text. You can convert it to ints using Integer.parseInt() We use BufferedReaders to minimize the number of reads to the file. The Buffer reads
More informationJOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide
Module 10 I/O Fundamentals Objectives Upon completion of this module, you should be able to: Write a program that uses command-line arguments and system properties Examine the Properties class Construct
More informationThe Singleton Pattern. Design Patterns In Java Bob Tarr
The Singleton Pattern Intent Ensure a class only has one instance, and provide a global point of access to it Motivation Sometimes we want just a single instance of a class to exist in the system For example,
More informationFacade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004
Facade and Adapter Comp-303 : Programming Techniques Lecture 19 Alexandre Denault Computer Science McGill University Winter 2004 March 23, 2004 Lecture 19 Comp 303 : Facade and Adapter Page 1 Last lecture...
More informationI/O in Java I/O streams vs. Reader/Writer. HW#3 due today Reading Assignment: Java tutorial on Basic I/O
I/O 10-7-2013 I/O in Java I/O streams vs. Reader/Writer HW#3 due today Reading Assignment: Java tutorial on Basic I/O public class Swimmer implements Cloneable { public Date geteventdate() { return (Date)
More informationInheritance E, xc Ex eptions ceptions I/O
Inheritance, Exceptions, I/O ARCS Lab. Inheritance Very Very Basic Inheritance Making a Game public class Dude { public String name; public int hp = 100 public int mp = 0; } public void sayname() { System.out.println(name);
More informationProject 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.
Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently. User Request: Create a simple movie data system. Milestones: 1. Use
More informationתוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת
תוכנה 1 תרגול 8 קלט/פלט רובי בוים ומתי שמרת A Typical Program Most applications need to process some input and produce some output based on that input The Java IO package (java.io) is to make that possible
More informationDecorator Pattern. Steven R. Bagley
Decorator Pattern Steven R. Bagley Introduction Decorator Pattern Inheritance vs. Composition Tricolour Coffee Bar Fast-growing coffee chain Started by a computer scientist Wants a fully OO based ordering
More informationCSE 143 Lecture 25. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides adapted from Marty Stepp
CSE 143 Lecture 25 I/O Streams; Exceptions; Inheritance read 9.3, 6.4 slides adapted from Marty Stepp http://www.cs.washington.edu/143/ Input and output streams stream: an abstraction of a source or target
More informationNotes - Recursion. A geeky definition of recursion is as follows: Recursion see Recursion.
Notes - Recursion So far we have only learned how to solve problems iteratively using loops. We will now learn how to solve problems recursively by having a method call itself. A geeky definition of recursion
More informationBasic Java IO Decorator pattern Advanced Java IO. Java IO - part 2 BIU OOP. BIU OOP Java IO - part 2
Java IO - part 2 BIU OOP Table of contents 1 Basic Java IO What do we know so far? What s next? 2 Example Overview General structure 3 Stream Decorators Serialization What do we know so far? What s next?
More informationCSE 143 Lecture 22. I/O Streams; Exceptions; Inheritance. read 9.3, 6.4. slides created by Marty Stepp
CSE 143 Lecture 22 I/O Streams; Exceptions; Inheritance read 9.3, 6.4 slides created by Marty Stepp http://www.cs.washington.edu/143/ Input and output streams stream: an abstraction of a source or target
More information