delegating - best practice

Hi, I have C# component that has a class as below:
namespace SharedComponent{
class TestResult {
//several members
}
}

In another existing C# application I am referencing this component and I need to instantiate this same class but with an additional identifier as below.

namespace ClientApplication {
class TestResult {
//exact same members as above including methods
//actually the shared component class was created by gleaming
//that from this application!
int PersonID; //additional identifier
            //not suitable to have in the shared component
}
}

In the client application there are several methods that rely on the additional identifier. So it is very tempting for me to emulate a copy constructor and create this object and fill in the additional parameter. This way I can use the existing functions as they are with minimal changes to the class.

Another way could be to add the rest of the details as a reference to the client side implementation.

namespace ClientApplication {
class TestResult {
SharedComponent.TestResult trshared = new SharedComponent.TestResult()
//but this warrants I have my class methods to delegate
//to the sharedcomponent throughout ; example below

internal bool IsFollowUp(ClientApplication.TestResult prevTest)
{
      //a similar method is being used
      //where a function takes the class object as parameter
      trshared.IsFollowUp(prevTest.trshared);
}

int PersonID; //additional identifier

}
}


Which option is better? What is the best practice in this regard?

Environment: VS2008, C#, WinXP/Win7
LVL 1
ol muserTechnology GeneralistAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
you should create a new class TestResultExtended, which INHERITS from TestResult, and add the new fields/methods to that

namespace ClientApplication {
class TestResultExtended : TestResult  {
internal bool IsFollowUp(ClientApplication.TestResult prevTest)
{
      //a similar method is being used
      //where a function takes the class object as parameter
      trshared.IsFollowUp(prevTest.trshared);
}

int PersonID; //additional identifier
...
}


that way ALL of the fields and methods from Test Result are automatically part of TestResultExtended, without you haiving to do anything.  That is how inheritance works.

AW
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.