Design advice needed

My question is: I dont know which creational design pattern to solve the problem below:

I have a "main" class I call Sentinel which monitors all the threads that are created. If any of the threads dont finish on time or died, the Sentinel will be able to detect this and report to user.

Let's take an example. Suppose we are creating a sentry simulation application where our objective is to use 1) a dog 2) a human guard 3) a motion sensor detector to guard an area. The "main" class is going to be Sentinel that has all those objects. Each object requires something different for it to work. A dog needs a dog food object, human needs money object, and motion sensor needs electricity object. NOTE: Since dog, guard, and motion sensor are all independent, they all derive from the Thread class.

So without knowing any creational pattern, I basically would (naively) implement it like this:

Inside Sentinel's Init() method, I have

Dog* dog = new Dog( food );
Guard* human = new Guard( money );
MotionSensor* ms = new MotionSensor( electricity );

assert( dog != NULL );
assert( human != NULL );
assert( ms != NULL );

this->AddThreadToWatch( dog);
this->AddThreadToWatch( human );
this->AddThreadToWatch( ms );

dog->Start(); human->Start(); ms->Start();

As you can see, and the pattern for each thread creation is:

1) "new" a thread, and pass thread-specific constructor parameters to it.
2) Check if "new" failed
3) add the successfully created thread to Sentinel list to watch.
4) Start() the thread.

I wish I could have "something" (what?) that would generically create whatever abstract class I want, so to solve these problems:
1) Reduce having to manually type all that for each thread I want to create.
2) Have a single point of thread/class creation.
3) If we used some kind of creational pattern, how do we take care of different constructor parameter?

Thanks, I think response to this problem will be very interesting; I've been dying to know!
[2143 byte] By [ShaChris23] at [2007-11-20 11:49:04]
# 1 Re: Design advice needed
Well, you *could* use a factory pattern easily enough. That'd be pretty straightforward to do; just create a class with newDog( dogfood food) functions, etc. However, it wouldn't scale easily.

Another option would be to include the sentinel->AddThread(this) call to the constructor, but that would require getting the sentinel in there. If it's a singleton, just giving it a static getInstance method would make that easy. And you'd still have the assert to handle individually.

If food, money, and electricity all derive from a common class, then that opens a number of additional options as well.
Lindley at 2007-11-9 1:26:14 >