22
33import java .util .Arrays ;
44
5+ /**
6+ *
7+ * <p>
8+ * Multilayered architecture is an architectural style where software responsibilities are
9+ * divided among the different layers of the application.
10+ * </p>
11+ *
12+ * <p>
13+ * This example demonstrates a traditional 3-layer architecture consisting of data access
14+ * layer, business layer and presentation layer.
15+ * </p>
16+ *
17+ * <p>
18+ * The data access layer is formed of Spring Data repositories <code>CakeDao</code>, <code>CakeToppingDao</code> and
19+ * <code>CakeLayerDao</code>. The repositories can be used for CRUD operations on cakes, cake toppings
20+ * and cake layers respectively.
21+ * </p>
22+ *
23+ * <p>
24+ * The business layer is built on top of the data access layer. <code>CakeBakingService</code> offers
25+ * methods to retrieve available cake toppings and cake layers and baked cakes. Also the
26+ * service is used to create new cakes out of cake toppings and cake layers.
27+ * </p>
28+ *
29+ * <p>
30+ * The presentation layer is built on the business layer and in this example it simply lists
31+ * the cakes that have been baked.
32+ * </p>
33+ *
34+ * <p>
35+ * We have applied so called strict layering which means that the layers can only access
36+ * the classes directly beneath them. This leads the solution to create an additional set of
37+ * DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>)
38+ * to translate data between layers. In other words, <code>CakeBakingService</code> cannot
39+ * return entities (<code>Cake</code>, <code>CakeTopping</code>, <code>CakeLayer</code>)
40+ * directly since these reside on data access layer but instead translates these into business
41+ * layer DTOs (<code>CakeInfo</code>, <code>CakeToppingInfo</code>, <code>CakeLayerInfo</code>)
42+ * and returns them instead. This way the presentation layer does not have any knowledge of
43+ * other layers than the business layer and thus is not affected by changes to them.
44+ * </p>
45+ *
46+ * @see Cake
47+ * @see CakeTopping
48+ * @see CakeLayer
49+ * @see CakeDao
50+ * @see CakeToppingDao
51+ * @see CakeLayerDao
52+ * @see CakeBakingService
53+ * @see CakeInfo
54+ * @see CakeToppingInfo
55+ * @see CakeLayerInfo
56+ *
57+ */
558public class App {
659
760 private static CakeBakingService cakeBakingService = new CakeBakingServiceImpl ();
861
62+ /**
63+ * Application entry point
64+ * @param args Command line parameters
65+ */
966 public static void main (String [] args ) {
1067
1168 // initialize example data
@@ -16,6 +73,10 @@ public static void main(String[] args) {
1673 cakeView .render ();
1774 }
1875
76+ /**
77+ * Initializes the example data
78+ * @param cakeBakingService
79+ */
1980 private static void initializeData (CakeBakingService cakeBakingService ) {
2081 cakeBakingService .saveNewLayer (new CakeLayerInfo ("chocolate" , 1200 ));
2182 cakeBakingService .saveNewLayer (new CakeLayerInfo ("banana" , 900 ));
0 commit comments