GofPatterns
SiteMap
Design Patterns Course
Behavioral Patterns
Creational Patterns
Structural Patterns
Structural Patterns
«Prev
Next»
Design Patterns
Defining Patterns
Three Types Design Patterns
Behavioral Creational Structural
Design Pattern Components
Design Pattern Benefits
Design Pattern Scope
Three Categories Patterns
Singleton Patterns
Singleton Pattern-Quiz
Real World Examples
Design Pattern Elements
Creational Patterns
Factory Method Consequences
Factory Method-Exercise
Common Creational Patterns
Structural Patterns
Structural Pattern Example
Patterns Help Programmers
Common Structural Patterns
Flyweight Pattern
Flyweight Consequences
GOF Structural Patterns
Adapter Bridge Composite
Flyweight Suitability
Behavioral Patterns
Define Behavioral Patterns
Mediator Pattern Applicability
Observer Pattern Tradeoffs
Designing Software
How to Choose Pattern
Combine Design Patterns
Design Pattern Limitations
How To Apply Pattern
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.
Submit