(Bit late to the party... still think this is worth saying and it might help you in future) If you ever find yourself wanting to use a class but there's aspects of it's interface that you don't want to work with then don't try and modify the class you want to use - that way lies madness and hackiness of the first degree. If the class with the relatively fat interface really needs a big interface somewhere else you don't want to break that. So what can you do about it? Wheel out the software engineer's swiss army knife - another level of indirection! So if you've got a class:
class fat_and_dangerous
{
public:
void safe();
void dangerous();
};
and don't want clients to use dangerous()
implement another class using it:
class skinny_and_safe
{
public:
skinny_and_safe() : fat_( new fat_and_dangerous ) {}
void safe() { fat\_->safe(); }
private:
std::unique\_ptr fat\_;
}
and in most of your client code only use skinny_and_safe
. Just out of interest... don't actually implement skinny_and_safe inline. It leaks too many implementation details to the client. Don't worry about performance - most compilers (actually linkers working with compilers) these days will elide the indirect call - until a profiler tells you that it's slow.