Skip to content

Commit 74aeae3

Browse files
committed
Section about example flaws in the demo
1 parent 360f9fb commit 74aeae3

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

documentation/modules/ROOT/pages/03-demo.adoc

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77

88
== Demonstration
99

10-
Let's take a look at the example.
10+
Let's take a look at the following example.
1111
We'll be looking at a Cabs ride-sharing application, that mimics real-world solutions of similar kind.
1212
The application is written in a popular Java framework.
1313

1414
=== Initial application
1515

16-
Here's a method from the Cabs application that handles the completion of transit:
17-
18-
[WARNING]
16+
[IMPORTANT]
1917
====
20-
The following example should be considered an anti-example!
18+
The following example should be considered as suboptimal, most likely a counterexample!
2119
====
2220

21+
Here's a method from the Cabs application that handles the completion of a ride.
22+
2323
[source,java]
2424
----
2525
@Transactional // <1>
@@ -51,16 +51,53 @@ public void completeTransit(Long driverId, UUID requestUUID, Address destination
5151
}
5252
----
5353

54-
There are a number of problems with that method:
54+
[CAUTION]
55+
====
56+
There are issues with the above method.
57+
58+
<1> It uses the `+@Transational+` annotation, and modify number of unrelated data stores.
59+
// This means that when one of those operations fails, the whole processing will be rolled back.
60+
// In effect, the end-user will receive a nasty error message.
61+
62+
<2> It merges different, business domains.
63+
// This makes it hard to understand and maintain.
64+
// It isn't required to all of those operations complete at the same time.
65+
====
66+
67+
Similar methods are, unfortunately, quite common in business applications.
68+
At first glance, many developers don't see any problems with similar code.
69+
Let's break down the problems in detail.
70+
71+
==== Overuse of transactional processing
5572

56-
<1> It uses the `+@Transational+` annotation, and modify number of data stores.
73+
The transactional processing has been the cornerstone of many business applications.
74+
However, in most cases, the transactional processing isn't the best fit for real-world processes.
75+
76+
In our example, when the ride finishes, that's a real-world situation.
77+
However, the example uses the `+@Transational+` annotation, and operate on number of unrelated data.
5778
This means that when one of those operations fails, the whole processing will be rolled back.
5879
In effect, the end-user will receive a nasty error message.
59-
<2> It merges different, business domains.
60-
This makes it hard to understand and maintain.
61-
It isn't required to all of those operations complete at the same time.
6280

63-
Include here content related to potential existing demos: blogs, articles, recorded videos, walkthrough guides, tutorials.
81+
[NOTE]
82+
====
83+
Outages from the dependant services must not invalidate the main intent.
84+
In fact, all the operations in this example could happen independently, and at different, yet reasonable times.
85+
====
86+
87+
==== Bundling of different logical domains
88+
89+
Our example is also very chatty, and hard to understand at first glance.
90+
In fact, this is quite common in similar applications.
91+
The code starts small, easy to understand.
92+
When new features are added, it keeps growing as developers cramp new instructions into methods like `+completeTransit+`.
93+
94+
Of course, the developers could re-architect the code, to extract instructions to a separate blocks, but that is just a half-measure.
95+
Still, the application will do all the operations, starting from `+completeTransit+` method in the same time, and withing the same _"script"_.
96+
97+
=== Refactoring
98+
99+
In this section, we'll refactor the Cabs application.
100+
The refactoring will be limited to make the process easy to understand.
64101

65102
image::https://www.plantuml.com/plantuml/svg/VP1DJiCm58JtFiMZ-rmWYwgqeHkeX2WNUBK7Ok4ubdyYzVQuZKbe5TZ5olTcFiqcHFOnTKOyn1OTIC8d0xPLdwBH5iBb_rfgnpRIwWMVBC_qwDoAED3ul4MUBKSzW9u6vES1eRsYMzz_mT-YZS-W3tJeLUwyOdlW23zeYJkK8vyuZ52p5O9bRk687uTYLgrB4zNqcav6XvPsR6GocTsZQ8d2L1aV3slQzVP3-uuKpCNgB1JkEwQpzI_FcjxoL5XgcUvdMioVL4soi-iuIOQcE5N259RYPgKYMNJ-3lfdkMPRqp7s7lJkjQFBvWihR61Lwimt[width=100%]
66103

0 commit comments

Comments
 (0)