From the course: Java Design Patterns: Structural

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Recognize where to use the Flyweight pattern

Recognize where to use the Flyweight pattern - Java Tutorial

From the course: Java Design Patterns: Structural

Start my 1-month free trial

Recognize where to use the Flyweight pattern

- [Instructor] This app, is a simulation of the number of cars in a given area. Simulations are often used in software to model systems in the real world, and they can be used to make predictions, so this one simulates traffic in a given area. First of all, there's an interface called vehicle, which defines three methods called, get type, get location, and set location. There are two concrete implementations of vehicle, one's called car and one's called truck. If I open up the car class, I can see that it has a field called location, which is an array of two integers. The set location method takes two integers as arguments and sets these as the values of array for the location. The get location method, returns the location field. Finally, there's a method called get type, which returns the string car. If I open up the truck class, which also implements vehicle, I can see that it's exactly the same as car, except that in…

Contents