View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 2 - Manini Patel

Difference between Creational, Structural and Behavioral patterns:
http://www.developer.com/design/article.php/3325211 , http://www.cmcrossroads.com/bradapp/docs/patterns-intro.html

We can divide patterns in three types:
  1. creational
  2. structural
  3. behavioral
Creational pattern: It creates objects rather than having user instantiate objects directly. Creational pattern gives more flexibility to program in deciding which objects are needed for a given case. These patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. The basic form of object creation could result in design problems or added complexity to the design. Creational design patterns solve this problem by somehow controlling this object creation.

Structural pattern: It helps the user to compose groups of objects into larger structure, such as complex user interfaces or accounting data. This pattern ease the design by identifying a simple way to realize relationships between entities.

Behavioral pattern: It helps the user in defining the communication between objects in the system. It shows the flow is controlled in a complex program. By doing so, these patterns increase flexibility in carrying out this communication.

Singleton Design Pattern:
http://en.wikipedia.org/wiki/Singleton_pattern , http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpatterns.html

Here I will describe singleton design pattern. It is an example of Creational pattern. Singleton pattern is most widely used design pattern. In computer Science, the singleton design pattern is designed to restrict instantiation of a class to one object. Singleton pattern is useful when exactly one object is needed to coordinate actions across the system. It is also considered as an Anti-pattern since it is often used as a global variable.

Singleton pattern is implemented by creating a class with a method that creates a new instance of the object if the object doesn’t exist. If object does exist then it returns a reference to that object. The constructor is made private or protected to make sure that the object cannot be instantiated.

In multi-threaded applications the Singleton pattern must be carefully constructed. If two threads are to execute the creation method at the same time when a singleton does not yet exist, they both must check for an instance of the singleton and then only one should create the new one. The solution for this problem is to use mutual exclusion on the class that indicates that the object is being instantiated.

These are some examples where singleton pattern could be used: GUI application, window managers, print spoolers, and filesystems.

With singleton pattern the user can:

Singleton pattern could be very useful when it comes to keeping track of something eg. history. Example of that could be a mouse click on a button or a printer. I will not use Singleton for milestone2 but I might for some other milestones.


Link to this Page