refactoring (base vs child)

C

csharpula csharp

Hello,

I have a follwoing problem:

I got a class with members and I need to add another 2 classes which
will be childeren of this class but memebers from base class will now be
part of one of the child class. How can I modify my code ,I mean where I
refer to base which doesn't have those members anymore (because they are
in child). What is the best way to refactor this? Thanks!
 
F

Family Tree Mike

csharpula said:
Hello,

I have a follwoing problem:

I got a class with members and I need to add another 2 classes which
will be childeren of this class but memebers from base class will now be
part of one of the child class. How can I modify my code ,I mean where I
refer to base which doesn't have those members anymore (because they are
in child). What is the best way to refactor this? Thanks!

I had trouble following your description. Does this illustrate your
question?

class Parent
{
public string Name {get; set}
}

public Child : Parent
{
// In this class, Name should not exist.
}
 
C

csharpula csharp

But the question is how can I cnahge the code that refers to Parent's
memebers (and there are a lot of references) while those fields are not
part of Parent anymore but part of Child?

Thanks
 
F

Family Tree Mike

csharpula said:
But the question is how can I cnahge the code that refers to Parent's
memebers (and there are a lot of references) while those fields are not
part of Parent anymore but part of Child?

Thanks

So, did you start with this?

public class A
{
public string Name {get; set;}
}

And you changed it to this?

public class A
{
}

public class B : A
{
public string Name {get; set;}
}

public class C : A
{
public string Name {get; set;}
}

And in your code you have a lot of places where you do this:

A a = new A();
a.Name = "Fred";

How do you know that the above piece should be a "B" rather than a "C"
in the new code? The code must change because an "A" no longer contains
a Name property.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top