Alexander Makarov / Yii core team / ASAPIRL
https://slides.rmcreative.ru/2023/verona-packages/TTL of the item is ~20 sec.
We cannot operate with high number of items:
Architecture is needed to deal with way too complex systems.
For our brain too complicated comes way too fast.
© 2000 Robert Martin
REP, CCP, CRP
ADP, SDP, SAP
The granule of reuse is the granule of release.
Group things, that are used by end user, together.
import java.io.ByteArrayOutputStream;
import java.io.IOException;
class Main {
public static void main(String[] args) throws IOException{
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write("my word".getBytes());
os.writeTo(System.out);
}
}
import java.stream.ByteArrayOutputStream;
import java.exceptions.IOException;
class Main {
public static void main(String[] args) throws IOException{
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write("my word".getBytes());
os.writeTo(System.out);
}
}
Classes that are changed together are packaged together
Classes that are changed together by a maintainer should go into the same package.
Classes that are used together are packaged together
If classes aren't used by end user separately, they belong to the same package.
On early stages focus on CCP and REP.
The dependency graph of packages must have no cycles
Cycles are causing cascading problems.
There is clue/graph-composer.
But (PR #45) should be applied to exclude non-interesting packages.
The less dependencies, the simpler everything is...
Or rethink the package...
Depend in the direction of stability
You can't build a stable thing on an unstable base.
I — Instability. 1 — unstable, 0 — stable.
E — Efferent (outgoing, fanout) Coupling.
Number of classes out of the package the package depends on.
A — Afferent (incoming, fanin) Coupling.
Number of classes out of the package that depend on the package.
A package abstractness should increase with stability
Stable packages are abstract.
Flexible packages are concrete.
X — abstractness, Y — instability.
Sometimes 0, 0 is OK. Strings, arrays, stdlib.
Distance from main line.
0 is good.
1 is bad.
Same as SOLID, these principles and metrics are not dogmas but tools.
Correct design results in explosive increase in the number of packages. It is scary.
Principles are there to keep you away from either left-pad or monolith.
These tools and principles should help you producing code that breaks less.