Skip to content

Latest commit

 

History

History
105 lines (75 loc) · 879 Bytes

mar5_virtualrefactoring.md

File metadata and controls

105 lines (75 loc) · 879 Bytes

Sometimes instead of virtualizing the differences, it is better to refactor the commonality (into helper functions):

Original Virtual Refactor Subroutines







int D1::f()
{
    common...;
    specialized...;
    same...;
}
int D2::f()
{
    common...;
    different...;
    same...;
}

int Base::f()
{
    common...;
    vf();
    same...;
}



int D1::vf() override
{

    specialized...;
    
}
int D2::vf() override
{

    different...;
    
}

void common()
{
    common...
}
void same()
{
    same...
}

int D1::f()
{
    common();
    specialized...;
    same();
}
int D2::f()
{
    common();
    different...;
    same();
}

Sometimes.