View this PageEdit this PageAttachments 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 - Jeff Watson


Part One: What is the difference between creational, structural, and behavioral patterns?

Creational design patterns "abstract the instantiation process." In such a design pattern, a system does not depend on how its objects are created, allowing objects in the system to vary both in structure and in functionality. The system may be configured either at compile-time or at run-time. Additionally, there are two types of creational design patterns: class (varies the class instantiated via inheritance) and object (instantiation delegated to another object). The Abstract Factory, Builder, Prototype, and Singleton design patterns are all object design patterns. Factory Method is a creational class design pattern.

Structural design patterns consider the ways in which classes and objects can fit together into larger structures. Because multiple inheritance involves taking several classes and forming one class(taking many different parts and forming one "structure"), it can be considered as a type of structural design pattern. When structural design patterns are implemented, object composition is more flexible and can change at run-time. In the object-scope, the Bridge, Composite, Decorator, Facade, Flyweight, and Proxy design patterns are structural. The Adapter design pattern is a structural design pattern in the class-scope.

Behavioral design patterns focus on the interconnection and interaction among objects. To make communication among objects flow as smoothly as possible, these design patterns look at algorithms and assign responsibility to objects. Whereas behavioral class patterns use inheritance, behavioral object patterns use object composition. There are many different behavioral design patterns. In the object scope exists the Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, and Visitor design patterns. The Interpreter and Template Method patterns are behavioral class design patterns.

Source: http://coronet.iicm.edu/sa/scripts/lesson12.htm

Part Two: Template Design Pattern

The Template design pattern is not only one of the more often used design patterns, but is also quite easy to implement. By creating an outline of an algorithm in the form of an abstract class, one can avoid unnecessary duplication of code among various subclasses that may share some methods/functionality. Functionality that is different for each of the classes can be implemented separately in each class, while functionality common to all classes is inherited. Even if different classes need to accomplish the same tasks but carry them out differently, these differences can be sorted out within each specific class. For example, in creating a program used to sort data, an abstract class (the template) may contain a method "sort()" and its subclasses determine how the sorting actually gets carried out by selecting which helper functions to use in conducting the sorting.

I am primarily interested in this pattern because it is so easy to implement. It makes sense to me because it is logical to use one class as a template and avoid duplicating code, thus saving time. I can definitely see using it in my coding, as I have used this pattern several times before in my code. Obviously, this code would be most useful when working with a program that requires multiple algorithms that share the same basic functionality, or that share the same basic goals but get these goals accomplished differently.

Source: http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/TemplatePattern.htm


Link to this Page