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 - Trevor Bentley

Part 1: What are the differences between creational, structural, and behavioral patterns?

A creational pattern, as its name suggests, is used to create new objects based on the input, and are usually used for dynamically creating objects that are not known about during compilation. Creational patterns often control the lifecycle of the objects they create. Structural design patterns define organization of objects, which includes relationships that allow specification of ownership and scope. Many structural patterns are used to define data storage and access. A behavioral pattern defines communication between objects. Behavioral patterns specify which objects can communicate with each other and the messages they understand.

Part 2: State design pattern

The state design pattern is used to dynamically change the behavior of an object based on its current state. The design pattern uses an object interface as a substitute for a simple variable. Instead of having a state variable and logic for each possible value of the variable you can store an object representing the current state that has its own handling method. The calling object can use the same call for every state.

The state pattern makes sense. It removes special case handling from the calling object, which makes the design more general and expandable. Adding new states does not require changing the calling object. This pattern can easily be used in my code, since state variables are extremely common. Any program that has multiple states with different behavior for each state can benefit from using this design.

Links to this Page