Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: typescript
typesabstractionfactorydependency-inversion
Have factories and getters return the interface, not the concrete class
Declare factory/getter return types as the abstraction so callers depend on the interface rather than the implementation.
PR: hegnar-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | public makeRepository(): ConcreteRepository { |
| 2 | return new ConcreteRepository(); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | public makeRepository(): IRepository { |
| 2 | return new ConcreteRepository(); |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)