let' have look at the uml diagram for the flyweight patternflyweightfactory +getflyweight(flyweight specificstate +shared_state +shared_action(specific_stateeach flyweight has no specific stateany time it needs to perform an operation on specificstatethat state needs to be passed into the flyweight by the calling code traditionallythe factory that returns flyweight is separate objectits purpose is to return flyweight for given key identifying that flyweight it works like the singleton pattern we discussed in python design patterns iif the flyweight existswe return itotherwisewe create new one in many languagesthe factory is implementednot as separate objectbut as static method on the flyweight class itself think of an inventory system for car sales each individual car has specific serial number and is specific color but most of the details about that car are the same for all cars of particular model for examplethe honda fit dx model is bare-bones car with few features the lx model has /ctiltcruiseand power windows and locks the sport model has fancy wheelsa usb chargerand spoiler without the flyweight patterneach individual car object would have to store long list of which features it did and did not have considering the number of cars honda sells in yearthis would add up to huge amount of wasted memory using the flyweight patternwe can instead have shared objects for the list of features associated with modeland then simply reference that modelalong with serial number and colorfor individual vehicles in pythonthe flyweight factory is often implemented using that funky __new__ constructorsimilar to what we did with the singleton pattern unlike singletonwhich only needs to return one instance of the classwe need to be able to return different instances depending on the keys we could store the items in dictionary and look them up based on the key this solution is problematichoweverbecause the item will remain in memory as long as it is in the dictionary if we sold out of lx model fitsthe fit flyweight is no longer necessaryyet it will still be in the dictionary we couldof courseclean this up whenever we sell carbut isn' that what garbage collector is for