1 00:00:00,530 --> 00:00:03,260 During the last video, we looked at a bunch of principles, 2 00:00:03,260 --> 00:00:08,490 including the separation of concerns, single responsibility, and loose coupling. 3 00:00:08,490 --> 00:00:11,297 All of that can seem really abstract without an example. 4 00:00:11,297 --> 00:00:15,332 Let's now take a peek at what it means for us in Giflib. 5 00:00:15,332 --> 00:00:19,291 [SOUND] In Giflib, we'll split our application into three layers, 6 00:00:19,291 --> 00:00:22,560 the web layer, data access layer, and service layer. 7 00:00:24,090 --> 00:00:28,881 [SOUND] The web layer will consist of the controllers we've already started as well 8 00:00:28,881 --> 00:00:32,434 as anything relating specifically to serving web content. 9 00:00:32,434 --> 00:00:38,490 The data access layer we'll name DAO, which stands for Data Access Object. 10 00:00:38,490 --> 00:00:42,130 Here we'll write one DAO class for each entity class. 11 00:00:42,130 --> 00:00:45,260 And its sole purpose will be to interact directly with Hibernate. 12 00:00:46,280 --> 00:00:49,420 This will be the place where we code all of our CRUD operations. 13 00:00:50,940 --> 00:00:53,090 Finally, we'll have a service layer. 14 00:00:53,090 --> 00:00:57,962 [SOUND] This layer will receive requests from a service client, which in our case 15 00:00:57,962 --> 00:01:02,485 is a controller, and it'll make any calls to the DAO that are necessary. 16 00:01:02,485 --> 00:01:05,103 This layer could also perform any computations or 17 00:01:05,103 --> 00:01:08,290 processing that are outside the realm of our model objects. 18 00:01:09,800 --> 00:01:12,930 Our layers will be structured as packages and we'll keep relationships 19 00:01:12,930 --> 00:01:16,920 between the packages tightly controlled and loosely coupled. 20 00:01:16,920 --> 00:01:20,660 What this means is that any time there's an interaction between the layers, 21 00:01:20,660 --> 00:01:24,550 that interaction will take place via interfaces, not classes. 22 00:01:26,110 --> 00:01:30,280 As we get the structure in place, you may see a redundancy in code. 23 00:01:30,280 --> 00:01:31,630 We'll create an interface and 24 00:01:31,630 --> 00:01:36,125 a class implementing that interface for each entity in our application. 25 00:01:36,125 --> 00:01:40,075 Know that this apparent repetition is in our best interest as we code 26 00:01:40,075 --> 00:01:45,105 an application that is more maintainable, extensible, reusable, and testable.