Στα γρήγορα...
Mid.cs:
using System;
using System.Data;
using System.Reflection;
namespace rousso
{
public abstract class Mid
{
virtual public DataSet GetData()
{
return null;
}
// factory
static public Mid GetMid(Type midType)
{
if (!midType.IsSubclassOf(MethodBase.GetCurrentMethod().ReflectedType))
throw new ApplicationException("I only create instaces of my sub-classes!");
return (Mid) Activator.CreateInstance(midType);
}
}
}
SMid.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace rousso
{
/// <summary>
/// Summary description for SMid.
/// </summary>
public class SMid : Mid
{
public SMid()
{
//
// TODO: Add constructor logic here
//
}
override public DataSet GetData()
{
DataSet dataSet = new DataSet();
//
// TODO: Write applicable code to fill the dataSet
//
return dataSet;
}
}
}
Αντίστοιχα και το AMid.cs και όποιο άλλο θες
Για να φτιάξεις ένα object:
Mid m = Mid.GetMid(typeof(SMid));
Εννοείται ότι μπορείς να βάλεις ό,τι overloads θέλεις και αντί να περνάς το Type να περνάς το Type Name σαν string κλπ Επίσης εννοείται ότι δεν έχω βάλει τις υπόλοιπες παραμέτρους που χρειάζεσαι για λόγους συντομίας..
got it?
rousso
rousso