jeudi 29 janvier 2015

Derive from a base class but not include a condition in the base class's method


The current code looks like this:



public class Details
{
Public void Populate()
{
WriteChapterDetails();
}

public void WriteChapterDetails()
{
if ( includeHighDetails)
{
\\Do something
}

if (includeLowDetails)
{
\\Do something
}
}
}


I now want to write a new class named HighDetails which will be copy of the Details class except I don't want it to go to the if (includeLowDetails) condition.


I am thinking of deriving a class from Details class like:



public class HighDetails()
{
Public void Populate()
{
WriteChapterDetails();
}

public void WriteChapterDetails()
{
if ( includeHighDetails)
{
\\Do something
}
}


The Details class is a huge class and I don't want to repeat all the methods in the HighDetails class. I want to derive from the Details class and somehow not include the LowDetails. How can I do that?





Aucun commentaire:

Enregistrer un commentaire