Dependency Rules
CODERU defines module structure and access rights through four reserved package names. Each name carries its own access semantics, enforced automatically at build time.
What is a Module?
In the CODERU context a module is a Java package together with all classes directly belonging to it and all its sub-packages (sub-modules). The package hierarchy therefore directly mirrors a module hierarchy.
A dependency from module A to module B exists whenever a class in A holds a static reference to a class in B — through a method call, inheritance, a field type, a parameter type, etc.
BASIS 1. Basic Rule
A module may only depend on its own direct sub-modules. Access to sibling modules or ancestor modules is not permitted.
Transitive access: If module A has access to module B, it also has access
to all descendants of B (children, grandchildren, …) — except impl sub-modules
(see IMPL rule).
Access right inheritance: Special access rights granted or revoked by the IMPL, COMMON, FACTORY, and API rules are inherited by all descendant modules. If module A gains access to module B through the COMMON rule, every sub-module of A also has that access.
In the diagram:
- (1)
p1 → p1.p2— allowed (parent accesses direct child) - (2)
p1 → p1.p2.p3— allowed (transitive access through p2) - (3)
p1 → p1.p2.p4— allowed (transitive access through p2) - (4)
p1.p2 → p1.p2.p3— allowed (parent accesses direct child) - (5)
p1.p2 → p1.p2.p4— allowed (parent accesses direct child) - (6)
p1.p2.p4 → p1.p2.p3— forbidden (sibling access) - (7)
p1.p2.p4 → p1.p2— forbidden (ancestor access) - (8)
p1.p2 → p1— forbidden (ancestor access)
IMPL 2. IMPL Rule — private implementation
Only the direct parent module may access an impl package
and all of its sub-packages. All other modules — including the grandparent — are
excluded.
This enforces the Information Hiding principle (Parnas, 1972) at the package level.
Move any class that is an internal implementation detail into an impl
sub-package and it becomes invisible to the rest of the codebase.
In the diagram:
- (1)
p1 → p1.p2— allowed (basic hierarchy) - (2)
p1 → p1.p2.impl— forbidden (grandparent may not access impl) - (3)
p1.p2 → p1.p2.impl— allowed (direct parent accesses impl) - (4)
p1 → p1.p2.impl.p3— forbidden (grandparent may not access impl's descendants) - (5)
p1.p2 → p1.p2.impl.p3— allowed (transitive access through impl)
Example: If extractor.csv.CsvParser is a private detail
of extractor, move it to extractor.impl.csv.CsvParser.
The grandparent module importer can no longer reach it.
COMMON 3. COMMON Rule — shared utilities
All sibling modules of a common package (and their
descendants, by inheritance of access rights) may access it. Modules in other parts
of the tree are not granted this access.
The position of a common package in the hierarchy determines its reach:
a top-level common is accessible everywhere; a deeply nested
common is accessible only within its immediate sibling subtrees.
In the diagram:
- (1)
p1.p6 → p1.p7.common— forbidden (not a sibling of p1.p7.common) - (2)
p1.p7.p4 → p1.p7.common.p2— allowed (sibling of common accesses its contents) - (3)
p1.p7.p4.p5 → p1.p7.common— allowed (inherited from parent p1.p7.p4)
Use case: Shared utility classes (parsers, converters, value objects) that must be reused across sibling modules but should not be exposed globally.
FACTORY 4. FACTORY Rule — wiring / DI
A factory module and all its descendants may access
all sibling modules, including impl siblings that are
otherwise restricted.
Think of factory as the counterpart to common:
while every sibling can read common, factory can read
every sibling.
In the diagram:
- (1)
p1.factory → p1.p2— allowed (sibling access) - (2)
p1.factory → p1.impl— allowed (factory may access impl sibling) - (3)
p1.factory.p6 → p1.impl.p4— allowed (inherited from parent p1.factory)
Use case: Dependency-injection / wiring code that must instantiate
concrete implementation classes without leaking them to the rest of the module.
The factory knows everything; callers only see the api.
API 5. API Rule — public interface
An api package is accessible from anywhere in the program —
subject to the following restrictions:
- The BASIS rule still applies: descendant modules may not access their ancestors.
- Sibling modules may not access a
factorymodule or any of its descendants — even if those descendants are namedapi. Thefactoryrestriction takes precedence over theapiaccessibility rule. - The IMPL rule still applies: only the direct parent (or sibling
factory) may accessimplsub-packages. - An
apimodule may not access its siblingcommonmodule.
In the diagram:
- (1)
p1.api → p1.common— forbidden (apimay not access its siblingcommon) - (2)
p1.common → p1.p2.api— forbidden (commonmay not access a sibling'sapi) - (3)
p1.api → p1.p2.api— forbidden (sibling modules may not access another module's subtree via the API rule) - (4)
p1.p5.api → p1.p2.api— allowed (apiis accessible from anywhere) - (5)
p1.p2.api.p3 → p1.p5.api— allowed (apiis accessible from anywhere) - (6)
p1.p5.p9 → p1.factory.api— forbidden (p1.factory.apiis a descendant offactory; the factory restriction takes precedence)
Use case: Independently deployable functional modules (adapters, domain modules, reusable toolboxes) that need to be consumed from across the entire application.
Rules at a glance
| Package name | Who can access it? | What can it access? |
|---|---|---|
impl |
Direct parent only (+ sibling factory) |
Own sub-modules |
common |
All siblings (and their descendants) | Own sub-modules |
factory |
Parent only (like any normal package) | All siblings including impl |
api |
Everywhere (with cycle-prevention restrictions) | Own sub-modules |
| any other name | Parent module only | Own direct sub-modules |