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 - Travis Shepherd

Question 1:
3.) How does choice of language affect the use of design patterns?

Design patterns are influenced by language in terms of feasability and ease of implementation. For example, implementing a singleton design "class" in languages that don't support private access modifiers is rather difficult since you cannot hide constructors from the programmer. In most newer programming languages, access modifiers give the flexibility of having a method return a static instance of an object, while allowing any others to be instantiated. Also, different implementations have various drawbacks and strengths. Some are better for inheritance, some are simple but not very robust, others work but aren't always true singletons.


Question 2:
Describe one design pattern or pattern language in your own words. Again, reference your sources. Explain what interests you about this pattern. Does it make sense to you? Can you see using it in your coding? If so, what for? If not, why not?

The factory design pattern allows object creation to occur properly in a polymorphic environment. If there are several classes that implement an interface, or derive from the same class, a factory is a good way to ensure that the appropriate subclass is created for the more general reference.
For example, if you make a game with a Piece class, from which BluePiece and RedPiece extend (probably not good design, but it illustrates the point), you will most likely be working with references to a Piece, even though the actual objects will either be of the BluePiece or RedPiece type. Using the factory to return the appropriate instance based on some given information keeps the management of these objects in one place. In the future if changes need to be made to the object creation steps, they are made in this one class and not in various others when instantiation is needed.

I like this pattern for its extreme use in object oriented polymorphic applications. I have used it many times in the past when implementing hierarchies of objects that have some common parent, but when each object needs different capabilities. This was very useful in CS 2335.


Links to this Page