How to name this key-oriented access-protection pattern?

前端 未结 4 825
花落未央
花落未央 2020-12-03 05:21

Apparently this key-oriented access-protection pattern:

class SomeKey { 
    friend class Foo;
    SomeKey() {} 
    // possibly non-copyable too
};

class B         


        
4条回答
  •  醉酒成梦
    2020-12-03 05:56

    I propose naming this the Badge Idiom, signifying a token presented upon request proving possession of authority. I believe that this is a better metaphor than those revolving around the term Key in many of the other answers here.

    'Key' is already fairly overloaded in programming terminology, conflating at least the notions of lookup and of restricted access. Furthermore, real keys usually operate individual locks, not the set of all locks from a manufacturer, and the accepting class in this pattern is a set not of locks but of self-protecting entities being asked to perform actions.

    'Badge' conveys the principle that the token grants authority to an entire class of other entities, not just a single object. The term may be too reliant on (US-centric?) police or security imagery, and I did consider terms like Subpoena or Warrant, but they seemed too focused on third party granting of access. Anyway, individuals with a given badge type can compel codified behaviors from the classes of individuals respecting those badges. I see the overall interaction like this:

    • A: This party's too loud. Turn down your stereo. (Presents badge)
    • B: Oh, OK, officer. (groan)

提交回复
热议问题