I think probably the most common case where I find reducing the level of access of inherited methods is in observers. Consider:
class FooObserver {
public:
virtual void OnSomethingHappened() = 0;
};
class SomethingInterestedInFoos : public FooObserver {
public:
....
private:
void OnSomethingHappened() override;
};
It's very rare that anything should be calling SomethingInterestedInFoos::OnSomethingHappened() directly; rather, it should usually only be accessed by things that are interested in FooObservers (likely Foos). And typically something calling OnSomethingHappened() directly on a SomethingInterestedInFoos is an indication that something is wrong.
We *could* say that this is questionable design, and offer the alternative:
class SomethingInterestedInFoos {
public:
....
private:
class FooObserverHelper : public FooObserver {
public:
FooObserverHelper(SomethingInterestedInFoos* owner) : owner_(owner) {}
void OnSomethingHappened() override { owner_->OnSomethingHappened(); }
private:
SomethingInterestedInFoos* owner_ = nullptr;
};
void OnSomethingHappened();
FooObserverHelper observer_helper_;
}
But at the same time, that's an awful lot of redirection to be able to satisfy the joint desire for a) not reducing level of access and b) not allowing things to call observer methods on direct objects.
I tend to think that, like many things, reducing level of access is acceptable and desirable in certain cases, and not in others, and I'd be happy to leave it up to reviewers.
Just my $0.02.
Cheers,
- Devlin