A
Alok Jain
This is a design / inheritance qus.
I have class Task.
This is a base class for some specific tasks
Say
WorkOrderTask : Task
TimeSheetTask : Task
Now Task has a function GetDetails() which gets all info about task. This
makes a database call.
I override this in the derived class. For implementing this in derived
class i see following 2 approaches.
Approach 1. WorkOrderTask .GetDetails()
{
Calls base.GetDetails(); to get base details, populates in the
object
Gets details specific to WorkOrderTask, populates in the object
returns;
}
Approach 2. WorkOrderTask .GetDetails()
{
Get details specific to WorkOrderTask as well as the base class
details, populates in the object
returns;
}
The problem with
Approach 1
I have to make 2 database calls.
Approach 2
If theres some change in base class I need to take care of these in all the
derived classes as well.
Whereas, Approach 1 is advantageous here as by modifying only the
Task.GetDetails funciton ( this is the base class ) function i have all the
values and i do not need to touch the derived classes.
Was thinking this might be a very common problem, so perhaps many of might
be able to guide me on the approach i must take here. Perhaps anything other
then the two i have talked about.
Thanks in advance
Sourabh
I have class Task.
This is a base class for some specific tasks
Say
WorkOrderTask : Task
TimeSheetTask : Task
Now Task has a function GetDetails() which gets all info about task. This
makes a database call.
I override this in the derived class. For implementing this in derived
class i see following 2 approaches.
Approach 1. WorkOrderTask .GetDetails()
{
Calls base.GetDetails(); to get base details, populates in the
object
Gets details specific to WorkOrderTask, populates in the object
returns;
}
Approach 2. WorkOrderTask .GetDetails()
{
Get details specific to WorkOrderTask as well as the base class
details, populates in the object
returns;
}
The problem with
Approach 1
I have to make 2 database calls.
Approach 2
If theres some change in base class I need to take care of these in all the
derived classes as well.
Whereas, Approach 1 is advantageous here as by modifying only the
Task.GetDetails funciton ( this is the base class ) function i have all the
values and i do not need to touch the derived classes.
Was thinking this might be a very common problem, so perhaps many of might
be able to guide me on the approach i must take here. Perhaps anything other
then the two i have talked about.
Thanks in advance
Sourabh