Base classes are useful way to group objects that share a common set of functionality. Base classes can provide a default set of functionality, while allowing customization though extension.
Abstract classes are inherently more versionable than interfaces because methods can be added with a default implementation without requiring all the derived classes to implement the method.
However, this is only appropriate where the object that needs to implement the interface would not have any other base class. For example, make IByteStream an interface so a class an implement multiple stream types. Make ValueEditor an abstract class because ValueEditor subclasses classes have no other purpose than to edit values.
The public interface of a base class should provide a rich set of functionality for the consumer of that class. However, customizers of that class often want to implement the fewest methods possible to provide that rich set of functionality to the consumer. To meet this goal provide a set of sealed public methods that call through to a single family method with the Impl suffix that provides implementations for such a method.
Public Control { // public void sealed SetBounds(int x, int y, int width, int height) { . SetBoundsImpl ( ); } public void sealed SetBounds(int x, int y, int width, int height, BoundsSpecified specified) { . SetBoundsImpl ( ); } protected virtual void SetBoundsImpl(int x, int y, int width, int height, BoundsSpecified specified) { //do the real work here. } }
public sealed class Runtime { private Runtime(); //prevents the class from being created public String GetCommandLine() {} // }