A design ( inheriteance / overriding ) question

Discussion in 'ASP .Net' started by sourabh, May 14, 2004.

  1. sourabh

    sourabh Guest

    Hi
    Perhaps this question does not fit in this news group but I need some advice
    and could not figure out where to post this.
    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
     
    sourabh, May 14, 2004
    #1
    1. Advertising

  2. sourabh

    Alok Jain Guest

    Performance vs Scalability Re: A design ( inheriteance / overriding ) question

    Dear Sourabh,

    I will be in favor of approach 1. As you have rightly mentioned approach 2
    puts an high dependency on class 2 which is inherited from class1. Approach
    2 assumes that it knows every attribute of class1, here if you change any
    attribute of class1 you will have to update class2. And I feel this also
    breaks the encapsulation for class1 (although due to inheritance
    relationship it has a legal way to do that).

    I agree that due to two database calls there will be performance impact in
    approach 1. But things are changing now and whenever we encounter a
    situation of Scalability versus Performance, we need toconsider that there
    is a higher cost with Scalability while with bigger machines Performance is
    not that big issue now.

    There could be one more hybrid approach where you can generate a single
    database call in Class2 but it delegates the responsibility of constructing
    Class1 dependent part (query construction and data population) to Class1
    itself. Never tried this but you can give it a try.

    Please let me know if any body has any idea on this.

    Thanks
    Alok

    "sourabh" <> wrote in message
    news:%...
    > Hi
    > Perhaps this question does not fit in this news group but I need some

    advice
    > and could not figure out where to post this.
    > 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
    >
    >
     
    Alok Jain, May 21, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dotnetprogram
    Replies:
    1
    Views:
    721
    Joey Powell
    Dec 27, 2003
  2. =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=

    CSS Question - Overriding or slimming down element styles

    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=, Nov 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,382
    =?Utf-8?B?bG91aXNlIHJhaXNiZWNr?=
    Nov 17, 2004
  3. Gonçalo Rodrigues

    Question about overriding new and delete

    Gonçalo Rodrigues, Feb 19, 2005, in forum: C++
    Replies:
    3
    Views:
    1,763
    Bushido Hacks
    Feb 20, 2005
  4. Allan Streib

    question about overriding method

    Allan Streib, Oct 29, 2003, in forum: Python
    Replies:
    0
    Views:
    306
    Allan Streib
    Oct 29, 2003
  5. Eric S. Johansson
    Replies:
    3
    Views:
    303
    George Sakkis
    Jun 14, 2006
Loading...

Share This Page