Senior · Design · Attribute data versus attribute execution

Design an annotation reader for route labels that avoids unexpected constructor effects.

Think through your answer before opening the explanation.

Runtime & concurrency

Reveal answer and reasoning

Specify the accepted attribute type, target members, positional and named arguments, and duplicate-label policy. Use metadata inspection when only those recorded values are needed, then validate them before building a route table. Keep actual method signature validation and authorization separate from label discovery. An attribute named Allowed or Route is a declaration of data, not an automatic permission to execute the associated member.

Test valid labels, missing or malformed names, duplicates, unrelated annotations, and unsupported methods. Add a constructor with a visible teaching effect in a bounded test to confirm that the metadata-only reader does not instantiate it. If a real framework requires live attribute objects, document and test that different path instead of pretending the costs and failure behavior are identical. The wrong design constructs every available attribute during a broad scan and assumes those constructors cannot perform work, throw, or retain state.

What a strong answer covers

  • Define a narrow metadata contract.
  • Avoid construction when data alone is sufficient.
  • Keep routing policy and execution validation separate.

Common pitfall

Executing arbitrary attribute constructors merely to read simple declared data.

Follow-up questions

  1. How would inherited annotations change selection?
  2. How would you preserve required metadata under trimming?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions