I'm trying to implement a factory pattern in my project, but it seems to work even without an abstract class behind it.
What am I doing wrong?
1)Product
public interface IDataBaseEntity
{
string ServerName
{
get;
set;
}
string Id
{
get;
set;
}
string Password
{
get;
set;
}
string Database
{
get;
set;
}
DataTable GetBarCodeTable();
}
2)Concrete Product
class SqlEntity : IDataBaseEntity
{
SqlController sqlController = new SqlController();
public string ServerName { get; set; }
public string Id { get; set; }
public string Password { get; set; }
public string Database { get; set; }
public string CurrentTable { get; set; }
public DataTable GetBarCodeTable()
{
return sqlController.ExtractBarCodeTable(this);
}
}
3)Creator
IDataBaseEntity dataBaseEntity = null;
private void Form2_Load(object sender, EventArgs e)
{
dataBaseEntity = CurrentEntity.GetCurrentIdentity();
barcodeView.DataSource = dataBaseEntity.GetBarCodeTable();
}
4)Concrete Creator
public static class CurrentEntity
{
public static IDataBaseEntity GetCurrentIdentity()
{
SqlEntity sqlEntity = new SqlEntity
{
ServerName = @"localhost\test",
Id = "sa",
Password = "psw",
Database = "dbname"
};
return sqlEntity;
}
}
In this way I can keep the user code separated from the implementing code, but i'm not using any abstract class. Where's the catch?
Aucun commentaire:
Enregistrer un commentaire