Is it good to subclass a class only to separate some functional parts?
- by prostynick
Suppose we have abstract class A (all examples in C#)
public abstract class A
{
private Foo foo;
public A() { }
public void DoSomethingUsingFoo()
{
//stuff
}
public void DoSomethingElseUsingFoo()
{
//stuff
}
//a lot of other stuff...
}
But we are able to split it into two classes A and B:
public abstract class A
{
public A() { }
//a lot of stuff...
}
public abstract class B : A
{
private Foo foo;
public B() : base() { }
public void DoSomethingUsingFoo()
{
//stuff
}
public void DoSomethingElseUsingFoo()
{
//stuff
}
//nothing else or just some overrides of A stuff
}
That's good, but we are 99.99% sure, that no one will ever subclass A, because functionality in B is very important.
Is it still good to have two separate classes only to split some code into two parts and to separate functional elements?