Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Discussion 2 - Hai Phan (gtg394v)
Part 1: The differences between creational, structural, and behavioral patterns?
a. Creational patterns:
Creational patterns define mechanisms to create objects in a manner suitable to situation. The creational pattern takes care of the lifecycle of the instantiated object. On implementing this pattern, we really do not know the actual class that is used. We find this helpful in solving complex design problems.
Some typical creational patterns are:
b. Structure pattern:
- Abstract Factory: creates an instance of several families of classes.
- Factory Method: creates objects without specifying the exact class of object to be created.
- Prototype: creates new objects by copying this prototype.
- Singleton: restricts instantiation of a class to one object only.
Structure pattern is the composition of objects and their organization to obtain new and varied functionality. This pattern makes the design easier by identifying a simple way to realize relationships between classes and objects in forming larger structures.
Some typical structure patterns are:
c. Behavioral patterns:
- Adapter: provides one interface for a class that is suitable to client’s requirement, by wrapping the original library.
- Proxy: is a class functioning as an interface to the actual object. When we need multiple copies of a complex object, just create one instance of complex object. Then, create multiple proxy objects that contain a reference to the single original complex object.
- Container pattern: objects are created to hold other objects. For example: Queues, FIFOs/stacks, buffers, shopping carts, and caches.
Behavioral pattern is an interaction between different objects. The interaction means that the objects are talking to each other.
Some typical behavioral patterns are:
- Command: gathering and packaging requests from client objects into a single object for processing.
- Iterator: allows traversing through all of the elements or parts contained in some other object. Traverse and access a list of objects is an example for this pattern.
Part 2: Describe an Interesting Pattern.
Singleton pattern is the one I choose to implement very often. There is one and only one instance of a class can exist in the program. It is implemented by create only one instance of an object and keep this instance remaining for whole lifetime of the program. If the instance already exists, just returns a reference to that instance. Singleton pattern is interesting me because it provides us a simple way to design and implement. However, we must be very careful in case of two processes are trying to create instance of a class at the same time when a singleton does not exist yet. I did use this pattern when I designed for the server in my project of CS2335 class (Online game project). Since there a lot of connections from clients trying to connect to server, I created a network interface class and initiated only one instance to that class which took care of all connections from clients. Thus, all data from clients were transferred on one channel. So, I did not have to keep track which connection belonged to which client.
Link to this Page