Modify your implementation to support different types of restrictions.
Possible restrictions are:
- BlockAccess: Block access to the resource.
- LogAccess: Do not block access, but log an alert that the user has accessed the resource. This alert is logged through a stubbed service call.
These restrictions are not mutually exclusive. You may want to block access and log access for the same content tag.
这题考的是 可扩展的设计能力 :限制不应该只是“二选一”的枚举,而应支持 组合 / 叠加 (同一 tag 同时 Log + Block)。面试官重点看:抽象是否干净、将来加新 restriction 是否容易、以及“同时命中多条限制”时你的 执行顺序与行为定义 是否清晰(比如先记 log 再 block,或两者都做)。
正文完