Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)

Slides:



Advertisements
Similar presentations
Containers and Components 1.Containers collect GUI components 2.Sometimes, want to add a container to another container 3.Container should be a component.
Advertisements

Object-Oriented Design & Patterns 2 nd edition Cay S. Horstmann Chapter 5: Patterns and GUI Programming CPSC 2100 Software Design and Development 1.
Winter 2007ACS-3913 Ron McFadyen1 Also known as publish/subscribe The essence of this pattern is that one or more objects (called observers or listeners)
Software Engineering 2003 Jyrki Nummenmaa 1 OBJECT ARCHITECTURE DESIGN These slides continue with our example application, based on the simplified.
OOP Design Patterns Chapters Design Patterns The main idea behind design patterns is to extract the high level interactions between objects and.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
1 Patterns & GUI Programming Part 2. 2 Creating a Custom Layout Manager Layout manager determines how components are arranged/displayed in a container.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
March Ron McFadyen1 Design Patterns In software engineering, a design pattern is a generally repeatable solution to a commonly-occurring problem.
Graphical User Interface (GUI) Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Spring 2010CS 2251 Design Patterns. Spring 2010CS 2252 What is a Design Pattern? "a general reusable solution to a commonly occurring problem in software.
MVC Fall 2005 OOPD John Anthony. Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
Object-Oriented Analysis and Design
Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Hwajung Lee.
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
More OOP Design Patterns
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse 2.
ITEC324 Principle of CS III Chapter 5 (Horstmann’s Book) Patterns and GUI Programming Modified from slides by Dr. Hwajung Lee.
Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.
Behavioral Patterns  Behavioral patterns are patterns whose purpose is to facilitate the work of algorithmic calculations and communication between classes.
MVC pattern and implementation in java
Design Patterns and Graphical User Interfaces Horstmann ,
MVC and MVP. References enter.html enter.html
Case Studies on Design Patterns Design Refinements Examples.
Java Swing, Events and MVC Optional Readings: Eckel’s Thinking in Java: Chap 14 (
ISP666 MVC & Design Patterns. Outline Review Event Programming Model Model-View-Controller Revisit Simple Calculator Break Design Patterns Exercise.
Computer Science 209 Introduction to Design Patterns: Iterator Composite Decorator.
(c) University of Washington08-1 CSC 143 Models and Views Reading: Ch. 18.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
GoF: Document Editor Example Rebecca Miller-Webster.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
CSC 480 Software Engineering Design With Patterns.
CS 151: Object-Oriented Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Manali Joshi1 The Observer Design Pattern Presented By: Manali Joshi.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Model View.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Java Swing, Events Readings: Just Java 2: Chap 19 & 21, or Eckel’s Thinking in Java: Chap 14 Slide credits to CMPUT 301, Department of Computing Science.
MiniDraw Introducing a Framework... and a few patterns.
Model-View-Controller A Design Pattern SE-2030 Dr. Rob Hasker 1 Based on slides written by Dr. Mark L. Hornick Used with permission.
Week 8 Building Graphical User Interfaces in Java Steps to create a GUI Swing GUI components Event handling Software Design Pattern Observer, Composite,
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Chapter 5 Patterns and GUI Programming -Part 1-. Pattern A pattern is a description of a problem and its solution that you can apply to many programming.
Chapter 5 Patterns and GUI Programming -Part 2-. COMPOSITE Pattern Containers and Components Containers collect GUI components Sometimes, want to add.
Chapter 5 Patterns and GUI Programming. Pattern A pattern is a description of a problem and its solution that you can apply to many programming situation.
Chapter 5 Patterns and GUI Programming -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.
Pattern and GUI Programming
Graphical User Interfaces
Observer Pattern Context:
Design Patterns Source: “Design Patterns”, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides And Created.
Observer Design Pattern
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Model-View-Controller
CS102 – Bilkent University
Design Patterns A Case Study: Designing a Document Editor
Model-View-Controller Patterns and Frameworks
Building Graphical User Interface with Swing a short introduction
Model-View-Controller (MVC) Pattern
Composite Pattern Context:
CSC 480 Software Engineering
Strategy Design Pattern
Introduction to Design Patterns
Advanced ProgramMING Practices
Advanced ProgramMING Practices
Model, View, Controller design pattern
CSC 480 Software Engineering
Presentation transcript:

Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)

The Pattern Concept Each pattern has –a short name –a brief description of the context –a lengthy description of the problem –a prescription for the solution

Desing patterns

Observer Some programs have multiple editable views Example: HTML Editor WYSIWYG view structure view source view Editing one view updates the other Updates seem instantaneous

Multiple view

Model/View/Controller Model: data structure, no visual representation Views: visual representations Controllers: user interaction

Model/View/Controller Views/controllers update model Model tells views that data has changed Views redraw themselves

Observer Pattern An object, called the subject, is source of events One or more observer objects want to be notified when such an event occurs. 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.

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

Layout Managers How it works Set layout manager JPanel keyPanel = new JPanel(); keyPanel.setLayout(new GridLayout(4, 3)); Add components for (int i = 0; i < 12; i++) keyPanel.add(button[i]);

Strategy Pattern Context A class can benefit from different variants for an algorithm Clients sometimes want to replace standard algorithms with custom versions Solution Define an interface type that is an abstraction for the algorithm Clients can supply strategy objects Whenever the algorithm needs to be executed, the context class calls the appropriate methods of the strategy object

Containers and Components Containers collect GUI components Sometimes, want to add a container to another container Container should be a component Composite design pattern Composite method typically invoke component methods E.g. Container.getPreferredSize invokes getPreferredSize of components

Composite Pattern Context Primitive objects can be combined to composite objects Clients treat a composite object as a primitive object Solution Define an interface type that is an abstraction for the primitive objects Composite object collects primitive objects Composite and primitive classes implement same interface type. When implementing a method from the interface type, the composite class applies the method to its primitive objects and combines the results

How to Recognize Patterns Look at the intent of the pattern Remember common uses (e.g. STRATEGY for layout managers, Observers for updating views) Implement examples for comon patterns