lx carmodel("fit lx"air=truecruise_control=truepower_locks=truetilt=trueid(lx lx carmodel("fit lx"id(lx lx air true the id function tells us the unique identifier for an object when we call it second timeafter deleting all references to the lx model and forcing garbage collectionwe see that the id has changed the value in the carmodel __new__ factory dictionary was deleted and fresh one created if we then try to construct second carmodel instancehoweverit returns the same object (the ids are the same)andeven though we did not supply any arguments in the second callthe air variable is still set to true this means the object was not initialized the second timejust as we designed obviouslyusing the flyweight pattern can be more complicated than just storing features on single car class when should we choose to use itthe flyweight pattern is designed for conserving memoryif we have hundreds of thousands of similar objectscombining similar properties into flyweight can have an enormous impact on memory consumption it is common for programming solutions that optimize cpumemoryor disk space result in more complicated code than their unoptimized brethren it is therefore important to weigh up the tradeoffs when deciding between code maintainability and optimization when choosing optimizationtry to use patterns such as flyweight to ensure that the complexity introduced by optimization is confined to single (well documentedsection of the code the command pattern the command pattern adds level of abstraction between actions that must be doneand the object that invokes those actionsnormally at later time in the command patternclient code creates command object that can be executed at later date this object knows about receiver object that manages its own internal state when the command is executed on it the command object implements specific interface (typically it has an execute or do_action methodand also keeps track of any arguments required to perform the action finallyone or more invoker objects execute the command at the correct time