Can we increase the re-usability for this key-oriented access-protection pattern:
class SomeKey {
friend class Foo;
// more friends... ?
SomeKey() {}
// possibly non-copyable too
};
class Bar {
public:
void protectedMethod(SomeKey); // only friends of SomeKey have access
};
To avoid continued misunderstandings, this pattern is different from the Attorney-Client idiom:
- It can be more concise than Attorney-Client (as it doesn't involve proxying through a third class)
- It can allow delegation of access rights
- ... but its also more intrusive on the original class (one dummy parameter per method)
(A side-discussion developed in this question, thus i'm opening this question.)