/24@yegor256 1
Аннотации — это зло
Yegor Bugayenko
Annotations Are Evil
/24@yegor256 2
“Егор в своем стиле: все
гондурасы, а я д’Артаньян.”
Д’Артаньян и три мушкетёра (1978)
/24@yegor256 3
“Попал как будто на выступление
лидера какой-то секты.”
The Evil Cult (1993)
/24@yegor256 4
“Автор — маньяк.”
The Silence of the Lambs (1991)
/24@yegor256 5
1000+
takes.org
14000+
jcabi.com
rultor.com
jare.io
since

1988
2007
250+
/24@yegor256 6
since 2014
/24@yegor256 7
Compiler: @Override, @Deprecated, @SuppressWarning
DI: @Inject, @Singleton, etc.
Serialization: @XmlElement, etc.
Validation: @NotNull, etc.
Behavior: @GET, @Transaction
AOP: @RetryOnFailure, @Cacheable
Unit testing: @Test, @Before, @Rule, etc.
Lombok: @ToString, @EqualsAndHashCode, etc.
Something else?…
/24@yegor256 8
class Page {
@GET
String index() {
return “Hello, world!”;
}
}
/24@yegor256 9
class Page {
String index(Request request) {
if (request.method().equals(“GET”)) {
return “Hello, world!”;
}
return “Method not allowed”;
}
}
/24@yegor256 10
class Page {
@GET
String index() {
return “Hello, world!”;
}
}
class Dispatcher {
String dispatch(Page page, Request request) {
if (request.method().equals(“GET”)
&& page.getClass().getMethod(“index”)
.isAnnotationPresent(GET.class)) {
return page.index();
}
return “Method not allowed”;
}
}
/24@yegor256 11
Page Dispatcher
/24@yegor256 12
Page
Dispatcher
1 upside down
/24@yegor256 13
Page
Dispatcher
2 unclear dependencies
???
/24@yegor256 14
—Ты BeanPostProcessor видишь?
—Нет.
—А он есть!
ДМБ (2000)
/24@yegor256 15
Page
3 no encapsulation
Data
/24@yegor256 16
HelloPage
GETPage
/24@yegor256 17
class HelloPage implements Page {
@Override
String index(Request request) {
return “200 Hello, world!”;
}
}
class GETPage implements Page {
private final Page page;
@Override
String index(Request request) {
if (request.method().equals(“GET”)) {
return page.index();
}
return “Method not allowed”;
}
}
/24@yegor256 18
procedural
/24@yegor256 19
object-oriented
/24@yegor256 20
Compiler: @Override, @Deprecated, @SuppressWarning
DI: @Inject, @Singleton, etc.
Serialization: @XmlElement, etc.
Validation: @NotNull, etc.
Behavior: @GET, @Transaction
AOP: @RetryOnFailure, @Cacheable
Unit testing: @Test, @Before, @Rule, etc.
Lombok: @ToString, @EqualsAndHashCode, etc.
/24@yegor256 21
/24@yegor256 22
Can I see the code?Можно ли посмотреть код?
/24@yegor256 23
The Shining (1980)
/24@yegor256 24
yegor256.com

Java Annotations Are Evil