Laboratory Three, Group Four: Christopher Howell and Christopher McNamara


The flyweight design pattern allows for instances of identical objects. These objects are called flyweights By implementing only one object saves disk space. The flyweight design pattern allows for the objects to be shared which enables the objects to be immutable. The singleton design pattern for just one object to be created and this object is called a singleton.


The interesting part of using the flyweigth design pattern was "that we could not create the objects using a constructor since a new object is created each time the constructor is called." By checking to see if the object exists in a table allows us to save memory and if the object is not already in the table then a new object is created. This is very nice since we do not have to worry about te creation and storing of the objects. The constructor in the singleton design pattern must be made private and the access must be made through a static method.


The strengths of the flyweight design pattern is that it can be used for small and or large items and it also allows for saving space. The strength of the singleton design pattern is that it just needs one single object which is used for everything and this saves a lot of space. The singleton weaknesses include an increase dependencies and this then makes the entire class less desirable. The weaknesses of the flyweight pattern is that it should only really be used if there is a lot of "sharing to justify the extra complexity of maintaining the related table."



Testing the singleton design pattern with a framework like JUnit can be misleading. Ideally, the unit tests should operate on "singleton" instances of the object under test to avios misleading states from earlier tests. However, JUnit would prefer to manage these singletons itself using set up and tear down methods. Since these methods create new instances of the object, a user created singleton will only return the same instance, which puts the user in a pickle. The programmer must be careful to manage state in either case.



The largest pitfalls involved with this and other labs is the malfunctioning state of the machines. I have found no machines in the lab that are properly staged for many of the tasks at hand during laboratory sessions.


Link to this Page