GofPattern
SiteMap
Design Patterns Course
Behavioral Patterns
Creational Patterns
Structural Patterns
Structural Patterns
«Prev
Next»
Design Patterns
Defining Patterns
Design Challenges
Pattern Concept
Design Pattern Components
Big-O Notation
Design Pattern Benefits
Three Types Design Patterns
Three Categories Patterns
Design Pattern Scope
Traffic Signals Project
Patterns Conclusion
Singleton Patterns
Design Pattern Elements
Intent Motivation
Pattern Applicability
Singleton Pattern Structure
Singleton 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
factory Pattern Summary
Structural Patterns
Structural Pattern Example
Patterns Help Programmers
Common Structural Patterns
Flyweight Pattern
Flyweight Consequences
Flyweight Suitability
Behavioral Patterns
Define Behavioral Patterns
Mediator Pattern Applicability
Observer Pattern Tradeoffs
Designing Software
How to Choose Pattern
How To Apply Pattern
Lessons Learned
Combine Design Patterns
Design Pattern Limitations
Traffic flow System
Course Conclusion
Flyweight Pattern - Exercise
The Flyweight Pattern
Objective:
Convert vehicles to Flyweights.
There are not really likely to be enough vehicles and pedestrians in our simulation to motivate the use of the Flyweight pattern. For the purposes of this project, we need to assume that the various
Vehicle
classes are immutable (that velocity is constant). A Factory Method is already used to create the instances. So it is quite easy to make the vehicles flyweights merely by subclassing
VehicleFactory
with a
FlyweightVehicleFactory
. More changes to the
Vehicle
class are required. Therefore, we will be doing this exercise mostly for the sake of practice. The
FlyweightVehicleFactory
class has exactly the same public interface as the
VehicleFactory
class you have seen before. Only the private implementation is different. I will leave it up to you whether or not to use this Flyweight version of the
VehicleFactory
or the concrete one you developed in the last module. Type your answer in the text area below and then click the
Submit
button to see the result.