The flyweight pattern (structural design pattern) is used when we need to create many similar objects. Using Flyweight pattern, we reduce the creation of multiple objects. It help save memory and improve performance
If we build a game that creates 1000 soldiers. There are two types of soldier: Sniper and Commando. When using Flyweight pattern, we create 2 objects only. No need to create 1000 objects
Implementation steps:
1. Create an abstract class Soldier
2. Create CommandoSoldier class that extends Soldier
3. Create SniperSoldier class that extends Soldier
4. Create SoldierFactory
Sur cette page du site, vous pouvez voir la vidéo en ligne Using Flyweight pattern in Java project durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Improve Your Programming skills 15 septembre 2020, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 103 fois et il a aimé 3 téléspectateurs. Bon visionnage!