GofPattern
SiteMap
Design Patterns Course
Behavioral Patterns
Creational Patterns
Structural Patterns
Behavioral Patterns
«Prev
Next»
Design Patterns
Defining Patterns
Design Challenges
Pattern Concept
Design Pattern Components
Big-O Notation
Design Pattern Benefits
Three Types Design Patterns
Design Pattern Scope
Traffic Signals Project
Patterns Conclusion
Singleton Patterns
Design Pattern Elements
Intent Motivation
Pattern Applicability
Singleton Pattern Structure
Singleton Pattern-Quiz
Participants Collaborations
Consequences Effects
Class Implementation
Real World Examples
Substitute Patterns
Extension Variation Pattern
Course Project
Perfect Singleton
Pattern Conclusion
Creational Patterns
Creational Design Pattern
Creational Pattern Uses
Common Creational Patterns
Factory Pattern
Factory Method-Exercise
Factory Method Structure
Factory Method Consequences
Structural Patterns
Structural Pattern Example
StructuralPatterns Help Programmers
Patterns Help Programmers
Common Structural Patterns
Flyweight Pattern Motivation
Flyweight Suitability
FlyweightPattern Structure
FlyweightConsequences
Class Vehicles Intersection
Structural Patterns Conclusion
Behavioral Patterns
Define Behavioral Patterns
BehavioralPatterns Help Programmers
Common Behavioral Patterns
Observer Pattern Motivation
ObserverStructure TimeObserver Interface
TimeClass AsObserved Object
Observer Pattern Tradeoffs
Problems Require Mediator
Mediator Pattern Applicability
Mediator Pattern Structure
Benefits Pitfalls MediatorPattern
MediatorClass Course Project
Behavioral DesignPatterns Conclusion
Designing Software
How to Choose Pattern
How To Apply Pattern
Lessons Learned
Combine Design Patterns
Design Pattern Limitations
Traffic flow System
Course Conclusion
Signal Mediator Class - Exercise
Course Project, Part 6
Objective:
Write a SignalMediator class for the intersection that manages the four lights.
The
SignalMediator
is responsible for queuing requests and making sure that each light is green for a minimum amount of time. Furthermore, the mediator should provide access to the individual lights. The basic algorithm you want to implement has seven states that are cycled through in the following order. You can play with the minimum and maximum times if you like, but you must keep this order.
State
East
West
North
South
walk request
Min
Max
1
Go
Go
Stop
Stop
false
120
Inf
2
Go
Go
Stop
Stop
true
0
60
3
Caution
Caution
Stop
Stop
true
12
12
4
Stop
Stop
Stop
Stop
true
5
5
5
Stop
Stop
Go
Go
false
60
60
6
Stop
Stop
Caution
Caution
false
20
20
7
Stop
Stop
Stop
Stop
false
5
5
1
Go
Go
Stop
Stop
false
120
inf
The
Inf
in state one means that the east-west lights stay green until a pedestrian on the north-south direction explicitly requests a walk signal. This is one of the most important classes in the system. It also offers many options for how it is written, so I am going to leave the exact details open. In the text area below, type or paste your answer and click the
Submit
button.