I'm trying to learn patterns and I'm stuck on determining how or where a Factory Pattern determines what class to instanciate. If I have a Application that calls the factory and sends it, say, an xml config file to determine what type of action to take, where does that logic for interpreting the config file happen?
THE FACTORY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myNamespace
{
public abstract class SourceFactory
{
abstract public UploadSource getUploadSource();
}
public class TextSourceFactory : SourceFactory
{
public override UploadSource getUploadSource()
{
return new TextUploadSource();
}
}
public class XmlSourceFacotry : SourceFactory
{
public override UploadSource getUploadSource()
{
return new XmlUploadSource();
}
}
public class SqlSourceFactory : SourceFactory
{
public override UploadSource getUploadSource()
{
return new SqlUploadSource();
}
}
}
THE CLASSES
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace myNamespace
{
public abstract class UploadSource
{
abstract public void Execute();
}
public class TextUploadSource : UploadSource
{
public override void Execute()
{
Console.WriteLine("You executed a text upload source");
}
}
public class XmlUploadSource : UploadSource
{
public override void Execute()
{
Console.WriteLine("You executed an XML upload source");
}
}
public class SqlUploadSource : UploadSource
{
public override void Execute()
{
Console.WriteLine("You executed a SQL upload source");
}
}
}