Architecture: Scalability VS Performance

  • Thread starter Thread starter Alok Jain
  • Start date Start date
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
 
What if you use a protected member to define the SQL command? Use the same
implementation to retreive the data, just have your derived classes change
the stored proc name or SQL query to make the right call. If the sturucture
of the data is inconsistent between the derived classes and the base class,
then maybe the base class can extract its info then send a message to the
derived classes with the raw data for the to just extract the rest.

1 database call, reuse of code.

--
Eric Marvets
Principal Consultant

the bang project

<shameless self promotion>

Email (e-mail address removed) for Information on Our Architecture and
Mentoring Services

</shameless self promotion>
 
If I understand this right This means that the base class takes care of its
members, it will have member which will define its attributes in the SQL
command and similarly we have another member (function) to assign values
from the returned result set.

class Task
{
protected string getAttributes()
{ return "TaskId,Description,...";
}

protected void setAttributes(DataReader dr)
{
//code to set respective attributes
}
}

class WorkerTask : Task
{

public void getDetail()
{
//construct sql
string sqlStr = "select D1, D2" + base.getAttributes();

//execute query

//call base.setAttributes to set base class attributes

}
}

At this time I don't see any implementation issue, I will like to hear if
there is some better approach.

Thanks again
Alok
 
Back
Top