M
MattC
I have a class hierarchy that is, for simplicity sake, two levels deep.
User -> MoreSpecificUser
In most cases it will only be necessary for me to retrieve information for
one or the other. I figure if I dont need all the data that the parrent has
to offer why get it.
So here was my solution, I have an interface that all classes must
implement, this exposes Save, Load and Delete.
If I want just the MoreSpecficUser data then I just call its Load() method.
If I want the parent info I call base.Load().
Fine the coupling is low and maintenance is easy.
Here's my only quibble. If I wanted to do this:
public class User: IMyInterface
{
public void Load()
{
//open db connection
//fill dataset
//unpack dataset and fill load object members
//close connection
}
}
public class MoreSpecficUser : User
{
//other interface implementations here
public override void Load()
{
base.Load();
//open db connection
//fill dataset
//unpack dataset and fill load object members
//close connection
}
}
As you acn see I've simply called the base Load method to get all the info
available to this user. However it involves TWO database connections. Now
this make life easy in terms of code maintenance and flexibility in the app
but not sure how comfortable I am about makng two connections to fill and
object.
User -> MoreSpecificUser
In most cases it will only be necessary for me to retrieve information for
one or the other. I figure if I dont need all the data that the parrent has
to offer why get it.
So here was my solution, I have an interface that all classes must
implement, this exposes Save, Load and Delete.
If I want just the MoreSpecficUser data then I just call its Load() method.
If I want the parent info I call base.Load().
Fine the coupling is low and maintenance is easy.
Here's my only quibble. If I wanted to do this:
public class User: IMyInterface
{
public void Load()
{
//open db connection
//fill dataset
//unpack dataset and fill load object members
//close connection
}
}
public class MoreSpecficUser : User
{
//other interface implementations here
public override void Load()
{
base.Load();
//open db connection
//fill dataset
//unpack dataset and fill load object members
//close connection
}
}
As you acn see I've simply called the base Load method to get all the info
available to this user. However it involves TWO database connections. Now
this make life easy in terms of code maintenance and flexibility in the app
but not sure how comfortable I am about makng two connections to fill and
object.