C# Crew: Justin's weekly help me with my homework thread....

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Is anyone familiar with setting upa factory model in C#?

I have to make a game of memory. the class with the game board uses strictly objects. It can not know whether the spaces are going to be strings, ints, or images.

I have to figure out how to use a factory model to do this.

Thanks! - Justin
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
That helps. Thanks.:)

I understand the model I think, but I am unsure how to go about it for my program.
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Alright, I got this from my professor:

interface IFactory {
object create ( parameters );
}

Now, any implementation of IFactory has to implement create() but does not have to tell what it really creates.

If you need the created objects to do something (e.g., be a Control) simply say so in IFactory by changing the return type of create().



 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: torpid
Is that a question or an FYI?


the above post was an FYI.

I have a class with the factory interface:

public interface IFactory
{
object Create(object newObject);
}

Then I have the create function in my main:

public object Create(object newObject)
{
return newObject;
}

But then I am unsure what to do with that in regards to my model (logic for the game) class.
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Hmm.. I think the idea is to have 3 factory classes, one that creates strings, one that creates integers, etc. It sounds a little weird but I don't know how else it would be done given the parameters you specified.
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: torpid
Hmm.. I think the idea is to have 3 factory classes, one that creates strings, one that creates integers, etc. It sounds a little weird but I don't know how else it would be done given the parameters you specified.


The professor siad that to change what type of object I want to just change the return type in the IFactory interface.