I'm planning the structure of a program and want to use several tiers. Do you think my approach is good or do you have some other suggestions?
// The Form is the View + Controller (Windows Forms standard behaviour, don't want to change it)
class FormCustomer
{
CustomerModel _customerModel;
void LoadCustomer()
{
Customer c = _customerModel.ReadCustomer(tbCustomer.Text);
ShowCustomer(c);
}
}
// The Model-Layer is for business Logic
class CustomerModel
{
StorageLayer _StorageLayer;
public Customer ReadCustomer(int id)
{
if (id < 0) throw new Exception("Invalid id");
Customer c = _StorageLayer.ReadCustomer(id);
if (c == null) throw new Exception("Customer not found");
return c;
}
}
// The StorageLayer ist a facade to all storage Methods
// See http://en.wikipedia.org/wiki/Facade_pattern for more details
class StorageLayer
{
SqlMethods _sqlMethods;
public Customer ReadCustomer(int id)
{
return _sqlMethods.ReadCustomer(id)
}
}
// The SqlMethods is one class (or maybe several classes) which contain
// all the sql operations.
class SqlMethods
{
public Customer ReadCustomer(int id)
{
string sql = "Select c.*, a.* From customers c left join addresses a where c.id = " + id; // Not optimized, just an example
IDataReader dr = ExecuteStatement(sql);
return FetchCustomer(dr);
}
}