Object Oriented Design & Patterns. Part 1

Similar documents
Design patterns for graphical user interface applications

Chapter 5: Patterns and GUI Programming

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Laying Out Components. What is Widget Layout?

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

No SVN checkout today. Object-Oriented Design

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Java. GUI building with the AWT

Graphical User Interfaces (GUIs)

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Agenda. Container and Component

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Containers and Components

Systems Programming Graphical User Interfaces

Part I: Learn Common Graphics Components

CSE Lab 8 Assignment Note: This is the last lab for CSE 1341

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

CS11 Java. Fall Lecture 4

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

Graphical User Interfaces. Comp 152

CS 2113 Software Engineering

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Introduction to the JAVA UI classes Advanced HCI IAT351

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

Dr. Hikmat A. M. AbdelJaber

Java Programming Lecture 6

Graphical User Interfaces. Swing. Jose Jesus García Rueda

CSC 161 SPRING 17 LAB 2-1 BORDERLAYOUT, GRIDLAYOUT, AND EVENT HANDLING

Parts of a Contract. Contract Example. Interface as a Contract. Wednesday, January 30, 13. Postcondition. Preconditions.

11/6/15. Objec&ves. RouleQe. Assign 8: Understanding Code. Assign 8: Bug. Assignment 8 Ques&ons? PROGRAMMING PARADIGMS

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

CS 251 Intermediate Programming GUIs: Components and Layout

Window Interfaces Using Swing. Chapter 12

encompass a group of features for building Graphical User Interfaces (GUI).

PIC 20A GUI with swing

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

GUI in Java TalentHome Solutions

Introduction to GUIs. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2014

Graphical User Interfaces in Java - SWING

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

To gain experience using GUI components and listeners.

Basicsof. JavaGUI and SWING

Sri Vidya College of Engineering & Technology

CSE 1325 Project Description

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

CS11 Java. Fall Lecture 3

Unit 6: Graphical User Interface

Swing - JButton. Adding buttons to the main window

Design Patterns. Command. Oliver Haase

Window Interfaces Using Swing Objects

CSC207H: Software Design Lecture 11

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

CSC207 Week 4. Larry Zhang

Window Interfaces Using Swing Objects

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CHAPTER 2. Java Overview

CS 180 Final Exam Review 12/(11, 12)/08

Solution register itself

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Java Applets / Flash

G51PGP Programming Paradigms. Lecture OO-14 More Design Patterns And Java Examples

Top-Level Containers

Building Graphical User Interfaces. Overview

Today. cisc3120-fall2012-parsons-lectiii.3 2

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

Part 3: Graphical User Interface (GUI) & Java Applets

Commands. Written commands can be reused, cataloged, etc. Sometimes they also contain "undo" commands, too.

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Graphical User Interfaces

Output in Window Systems and Toolkits

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

A reusable design concept

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

Graphic User Interfaces. - GUI concepts - Swing - AWT

Human-Computer Interaction IS4300

Layout. Dynamic layout, Swing and general layout strategies

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Last Lecture. Lecture 17: Design Patterns (part 2) Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 4448/ Spring Semester, 2005

Building Graphical User Interfaces. GUI Principles

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Swing from A to Z Using Focus in Swing, Part 2. Preface

Java Swing. Lists Trees Tables Styled Text Components Progress Indicators Component Organizers

INTRODUCTION TO (GUIS)

Tecniche di Progettazione: Design Patterns

Introduction. Introduction

Software Eningeering. Lecture 9 Design Patterns 2

Calculator Class. /** * Create a new calculator and show it. */ public Calculator() { engine = new CalcEngine(); gui = new UserInterface(engine); }

UI Software Organization

Chapter 7: A First Look at GUI Applications

Transcription:

Object Oriented Design & Patterns Part 1 1

Design Patterns Derived from architectural patterns: rules for design of buildings describe common problems, solutions to those problems OO design patterns convenient way of reusing OO code between projects, programmers catalog common interactions between objects that programmers have found useful 2

Design Patterns Each pattern includes: description of problem context prescription for solution Idea is to distill a design rule into a simple format 3

Example: Iterators An iterator is a method or set of methods applied to an aggregate data structure (such as a linked list) Iterator provides access to structure members without requiring knowledge of internal structure details 4

Iterator Pattern: Context An aggregate object contains element objects Clients need access to the element objects The aggregate object should not expose its internal structure Multiple clients may want independent access 5

Iterator Pattern: Solution Define an iterator that fetches one element at a time Each iterator object keeps track of the position of the next element If there are several aggregate/iterator variations, it is best if the aggregate and iterator classes realize common interface types. 6

Iterator Pattern 7

Iterator pattern example: linked list Design pattern name: Aggregate ConcreteAggregate Iterator ConcreteIterator createiterator() next() isdone() currentitem() Actual name: List LinkedList ListIterator anonymous class implementing ListIterator listiterator() next() opposite of hasnext() return value of hasnext() 8

Model/View/Controller architecture Describes interaction of objects in a user interface with multiple editable views Example: PowerPoint outline view slide view notes view slide sorter view Edit in one view updates another; seems instantaneous 9

Model/View/Controller architecture Model: data structure, no visual representation (example: array) Views: visual representations drawn using specific format for example, number table Vs. bar chart Controllers: user interaction 10

Model/View/Controller architecture Each aspect has discrete responsibilities: Views/controllers update model Model tells views that data has changed Views redraw themselves 11

Model/View/Controller architecture 12

Model/View/Controller architecture Minimizes coupling between models, views & controls model has no knowledge of views; just knows to notify them of change views know nothing about controllers easy to add more views to model easy to change controller of a view Views are example of Observer pattern 13

Observer Pattern Model notifies views when something interesting happens Button notifies action listeners when something interesting happens Views attach themselves to model in order to be notified Action listeners attach themselves to button in order to be notified Generalize: Observers attach themselves to subject 14

Observer Pattern Context An object, called the subject, is source of events One or more observer objects want to be notified when such an event occurs. 15

Observer Pattern Solution Define an observer interface type. All concrete observers implement it. The subject maintains a collection of observers. The subject supplies methods for attaching and detaching observers. Whenever an event occurs, the subject notifies all observers. 16

Observer Pattern 17

Observer pattern example: Swing buttons Pattern name: Subject Observer ConcreteObserver attach() notify() Actual name: JButton ActionListener ActionListener implementor addactionlistener() actionperformed() 18

Layout Managers User interfaces made up of components Components placed in containers; need to arrange components Swing doesn't use hard-coded pixel coordinates Advantages: Can switch "look and feel" Can internationalize strings Layout manager controls arrangement 19

Standard Layout Managers: FlowLayout Components are laid out left to right; when a row is full, a new row is started 20

Standard Layout Managers: BoxLayout Components are laid out left to right or top to bottom 21

Standard Layout Managers: BorderLayout Default layout manager for Jframes Defines 5 areas: Center, North, South, East, West Don t have to place a component in every area Areas are sized according to need of component 22

Standard Layout Managers: BorderLayout 23

Standard Layout Managers: GridLayout Components laid out in grid, all same size 24

Standard Layout Managers: GridBagLayout Complex set of cells contain components Similar to HTML table 25

Using Layout Managers Create container Panel p = new Panel(); Set layout manager p.setlayout(new GridLayout(4,4,3,3)); Add components p.add(darken); 26

Using Layout Managers 27