<<interface>> Strategy

Slides:



Advertisements
Similar presentations
GoF State Pattern Aaron Jacobs State(305) Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Corresponds with Chapter 12
SWE 4743 Strategy Patterns Richard Gesick. CSE Strategy Pattern the strategy pattern (also known as the policy pattern) is a software design.
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.
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
1 CSE 331 The Strategy and State Patterns slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Applets, AWTS CompSci 230 Software Construction.
Design Patterns and Graphical User Interfaces Horstmann ,
02 - Behavioral Design Patterns – 2 Moshe Fresko Bar-Ilan University תשס"ח 2008.
Computer Science 209 The Strategy Pattern I: Comparisons and Layouts.
CSE 219 Computer Science III Graphical User Interface.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 12.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
 2002 Prentice Hall, Inc. All rights reserved Introduction Graphical User Interface (GUI) –Gives program distinctive “look” and “feel” –Provides.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
CS Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /20/2015 GUI - Graphical User Interface.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
CS 4244: Internet Programming User Interface Programming in Java 1.0.
Pattern Bridge. Definition Bridge is the structural pattern that separates abstraction from the implementation so that both of them can be changed independently.
AWT Layout Managers (Chapter 10) Java Certification Study Group January 21, 1999 Mark Roth.
Decorator Design Pattern Phillip Shin. Overview Problem Solution Example Key points.
CS 5150 Software Engineering Lecture 16 Program Design 3.
User Interface Components. Layout Placement of UI components in a window – Size & Position Each component occupies a rectangular region in the window.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
STRATEGY PATTERN By Michelle Johnson. BACKGROUND Behavioral Pattern Allow you to define a family of algorithms, encapsulate each one, and make them interchangeable.
The State Design Pattern A behavioral design pattern. Shivraj Persaud
Csci 490 / Engr 596 Special Topics / Special Projects Software Design and Scala Programming Spring Semester 2010 Lecture Notes.
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
1 A Quick Java Swing Tutorial. 2 Introduction Swing – A set of GUI classes –Part of the Java's standard library –Much better than the previous library:
GUI Programming In Java Sagun Dhakhwa BIM, HSM. GUI Appllications Event Driven OOP Uses objects of Classes like in any other Java programming.
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 -Part 2-. STRATEGY Pattern Layout Managers What if we need to specifies pixel position of components when  User.
A Quick Java Swing Tutorial
Pattern and GUI Programming
Graphical User Interfaces
Observer Pattern Context:
Design Patterns: MORE Examples
Java SWING and Model View Controller (MVC)
Graphical User Interfaces
Strategy Design Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Applying the Principles
Modern Programming Language Java
A Quick Java Swing Tutorial
object oriented Principles of software design
What is MVC Category: System MVC=Model-View-Controller
Design Patterns in Swing and AWT
Design Patterns in Swing and AWT
Model-View-Controller
Containers and Components
Creating Graphical User Interfaces
State Design Pattern 1.
Panels & Layout Managers
Object Oriented Design Patterns - Creational Patterns
Composite Pattern Context:
08/15/09 Decorator Pattern Context: We want to enhance the behavior of a class, and there may be many (open-ended) ways of enhancing the class. The enhanced.
Steps to Creating a GUI Interface
Design pattern Lecture 9.
A Quick Java Swing Tutorial
Strategy Design Pattern
Strategy Design Pattern
Design by Abstraction (Continuation) CS 3331 Spring 2005
Design Patterns (Gamma, Helm, Johnson, Vlissides)
Activity 1 - Chapter 5 -.
Software Design Lecture : 28.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

<<interface>> Strategy 08/15/09 Strategy Pattern Context: A class requires some behavior, but there are many ways that this behavior can be implemented. Solution: implement the behavior in a separate class, called the Strategy. Create a Strategy interface to de-couple the context class from the Strategy. Delegate the task to the strategy. <<interface>> Strategy +doSomething( Context ) ... Context - strategy: Strategy +setStrategy( Strategy) What are some examples of this? ConcreteStrategy +doSomething( ) ... AnotherStrategy +doSomething( ) ...

Container uses Strategy Pattern 08/15/09 Container uses Strategy Pattern Context: Swing container. Strategy: LayoutManager. Create a Strategy interface to de-couple the context class from the Strategy. Container - strategy: LayoutManager +add( Component ) +setLayout( LayoutManager ) <<interface>> LayoutManager +layoutContainer(Container ) ... What are some examples of this? BorderLayout +layoutContainer( ) ... FlowLayout +layoutContainer( ) ...

Using the Strategy Pattern 08/15/09 Using the Strategy Pattern (1) The application creates a concrete strategy and assigns it to the context. (2) The context delegates some work to the Strategy. Strategy : Context create cs : ConcreteStrategy setStategy(cs) doSomething( ) doSomething( context )

Strategy Pattern for Coin Purse 08/15/09 Strategy Pattern for Coin Purse Context: A coin purse must decide what coins to withdraw; there are many ways to do this and we may want to change strategies. Solution: Separate the withdraw( ) method from the Purse. Define a WithdrawStrategy interface for the withdraw operation, and modify the purse to delegate the withdraw operation to a concrete instance of WithdrawStrategy. CoinPurse - strategy: WithdrawStrategy +setWithdrawStrategy( ws ) +withdraw( amount ) WithdrawStrategy +withdraw( context, amount ) GreedyWithdraw +withdraw( ) ... RecursiveWithdraw +withdraw( ) ...

Strategy needs access to Context 08/15/09 Strategy needs access to Context To do its job, the Strategy usually needs a reference to the Context or some data of the Context. Container setlayout(LayoutManager lm) Context: AWT/Swing Container (JPanel ...) contains components. Strategy: A LayoutManager arranges and resizes components. LayoutManger needs a reference to Container to get size and list of Components. LayoutManager layoutContainer(Container c) BorderLayout