Behavioral_Patterns_6

Behavioral_Patterns_6 - Behavioral Patterns Behavioral...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Behavioral Patterns Behavioral Patterns • Chain of Responsibility • Command • Little Language • Mediator • Snapshot • Observer • State • Null Object • Strategy • Template Method • Visitor Behavioral Patterns • Behavioral patterns are used to organize, manage, and combine behavior. Chain of Responsibility • The chain of responsibility pattern allows an object to send a command without knowing what object or objects will receive it. • It accomplishes this by passing the command to a chain of objects that is typically part of a larger structure. • Each object in the chain may handle the command, pass the command on to the next object in the chain, or do both.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 class TemperatureSensor extends Sensor { private SecurityZone zone; void notify(int measurement) { zone.notify(measurement, this); } // notify(int) public interface SecurityZoneIF { public void notify(int measurement, Sensor source) ; public void fireAlarm(SecurityZone zone) ; } // interface SecurityZoneIF abstract class SecurityZone implements SecurityZoneIF { private SecurityZone parent; SecurityZone getParent() { return parent; } // getParent() public void notify(int measurement, Sensor sensor) { parent.notify(measurement, sensor); } // if } // notify(int, Sensor) protected abstract boolean handleNotification(int measurement, Sensor sensor); public void fireAlarm(SecurityZone zone) { if (parent != null) parent.fireAlarm(zone); } // fireAlarm(SecurityZone) } // class SecurityZone class Area extends SecurityZone { protected boolean handleNotification(int measurement, Sensor sensor) { if (sensor instanceof TemperatureSensor) { if (measurement > 150) { fireAlarm(this); return true; } } return false; } // handleNotification(int, Sensor) } // class Area class Warehouse extends SecurityZone { protected boolean handleNotification(int measurement, Sensor sensor) { return false; } // handleNotification(int, Sensor) public void fireAlarm(SecurityZone zone) { if (zone instanceof Area) { if (getParent() != nul ) getParent().fireAlarm(zone); return; } super.fireAlarm(zone); } // fireAlarm(SecurityZone) } // class Warehouse Command • Encapsulate commands in objects so that you can control their selection and sequencing, queue them, undo them, and otherwise manipulate them.
Background image of page 2
3 ... CommandFactory createCommand(name:String):AbstractCommand Creates Creates Creates GUIComponent commandName:String ... Invoke-command-by-name AbstractCommand ConcreteCommand1 ConcreteCommand2 1..* 1 1 1 1 0..* 0..* public abstract class AbstractCommand { /** * The CommandManager that manages command objects. */
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/17/2012 for the course GCIS 518 taught by Professor Tang during the Spring '10 term at Gannon.

Page1 / 10

Behavioral_Patterns_6 - Behavioral Patterns Behavioral...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online