Can we increase the re-usability of this key-oriented access-protection pattern?

Viewed 5781

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.)

3 Answers
Related