Skip to Content.
Sympa Menu

gang-of-4-patterns - Re: [gang-of-4-patterns] Altering a Strategy....does this seem right?

gang-of-4-patterns AT lists.cs.illinois.edu

Subject: Design Patterns discussion

List archive

Re: [gang-of-4-patterns] Altering a Strategy....does this seem right?


Chronological Thread 
  • From: A Rick Anderson <arick AT pobox.com>
  • To: gang-of-4-patterns AT cs.uiuc.edu
  • Subject: Re: [gang-of-4-patterns] Altering a Strategy....does this seem right?
  • Date: Sat, 15 Nov 2003 20:02:34 -0500
  • List-archive: <http://mail.cs.uiuc.edu/pipermail/gang-of-4-patterns/>
  • List-id: Design Patterns discussion <gang-of-4-patterns.cs.uiuc.edu>

Chris Finlayson wrote:

So, more specifically, what I'd propose to satisfy these requirements are:

1. Change the SortFactoryStrategy method by adding two new Create methods.
One that takes in a request of whether or not the user wants a stable or
nonstable algorithm, and a default one is created and returned. Another
that allows the user to request a specific type of stable or nonstable sort.

2. The factory then returns it appropriately. If one is not found, a Null
object is returned and a client has to check for that appropriately.


This allows for the ability to create stable and non-stable versions of
sorting routines (i.e. traditionally quicksort is non-stable, but a stable
version can be created).

That's a reasonable solution for early binding languages. However, if you look at how Gosling solved this in the examples that come with the JDK, you see how he was able to bypass the need for a factory class completely by passing in the name of the class he wanted to instantiate. With Java, and some of the other languages, you can instantiate an object from the name of the class.

--
A. Rick Anderson

arick AT pobox.com
arick AT bea.com





Archive powered by MHonArc 2.6.16.

Top of Page