1 00:00:00,130 --> 00:00:01,770 Welcome back, Ashley here. 2 00:00:01,770 --> 00:00:03,610 Let's move forward with our library app. 3 00:00:03,610 --> 00:00:06,640 So far we've declared three classes, library, book and 4 00:00:06,640 --> 00:00:09,450 patron, each one in their own js file. 5 00:00:09,450 --> 00:00:13,190 When I'm building out an object oriented app, I like to follow my rough plan and 6 00:00:13,190 --> 00:00:16,240 build out my constructor methods for each class first. 7 00:00:16,240 --> 00:00:20,740 As a quick recap a constructor method is where we tell the class, the properties. 8 00:00:20,740 --> 00:00:23,860 And the property's initial values that any new object 9 00:00:23,860 --> 00:00:25,660 of that class type should have available to them. 10 00:00:27,070 --> 00:00:30,850 Building the constructor methods first let's me instantiate a few test objects 11 00:00:30,850 --> 00:00:31,620 right off the bat. 12 00:00:31,620 --> 00:00:34,830 That I can plug some data into and play with as I go. 13 00:00:34,830 --> 00:00:38,810 This gives me a way to make sure that my code is working properly along the way. 14 00:00:38,810 --> 00:00:40,380 So that's what we'll be doing next. 15 00:00:40,380 --> 00:00:43,750 Building out the constructor methods for the library, book and patron classes. 16 00:00:44,800 --> 00:00:46,430 Let's start with the library class. 17 00:00:46,430 --> 00:00:50,020 To recap, according to our rough plan, the library class has two properties, 18 00:00:50,020 --> 00:00:51,890 books and patrons. 19 00:00:51,890 --> 00:00:55,410 These are going to be initialized to empty arrays in our constructor method. 20 00:00:55,410 --> 00:00:57,560 That's because the library doesn't have any books or 21 00:00:57,560 --> 00:00:59,334 patrons yet, it's a clean slate. 22 00:00:59,334 --> 00:01:02,880 A user of our library system can add books and 23 00:01:02,880 --> 00:01:06,570 patrons to these arrays, through the methods relayed out in our rough. 24 00:01:06,570 --> 00:01:08,810 AddBook and addPatron. 25 00:01:08,810 --> 00:01:11,920 This means we don't have to pass anything into our constructor method for 26 00:01:11,920 --> 00:01:13,370 the library class. 27 00:01:13,370 --> 00:01:16,520 As for our book class, we're going to be initializing a few properties 28 00:01:16,520 --> 00:01:18,510 in the constructor method as well. 29 00:01:18,510 --> 00:01:19,450 Just so you know, 30 00:01:19,450 --> 00:01:23,150 properties don't have to be initialized inside a constructor method. 31 00:01:23,150 --> 00:01:27,820 They can be initialized, like any variable, in a method on a class as well. 32 00:01:27,820 --> 00:01:30,930 If that's the case, that means an object of that class type 33 00:01:30,930 --> 00:01:33,910 will only have those properties if that method is called on. 34 00:01:35,110 --> 00:01:37,700 Our rough plan says that the book class will have the properties for 35 00:01:37,700 --> 00:01:40,320 title, author and isbn. 36 00:01:40,320 --> 00:01:42,260 All of these values will need to be passed in. 37 00:01:43,400 --> 00:01:45,870 Finally, let's talk about the patron class. 38 00:01:45,870 --> 00:01:48,760 The properties initialized in the constructor method are name, 39 00:01:48,760 --> 00:01:50,610 email and currentBook. 40 00:01:50,610 --> 00:01:51,780 The values for the name and 41 00:01:51,780 --> 00:01:55,530 email properties will be passed in when a patron object is created. 42 00:01:55,530 --> 00:01:59,010 In the real world, the patron will be providing that information to the library 43 00:01:59,010 --> 00:02:01,440 employee who keys it into the system. 44 00:02:01,440 --> 00:02:04,560 The currentBook property, however, is a little different. 45 00:02:04,560 --> 00:02:07,150 A patron won't have checked out a book when they are first entered into 46 00:02:07,150 --> 00:02:08,110 the system. 47 00:02:08,110 --> 00:02:10,060 So when the new patron object is created, 48 00:02:10,060 --> 00:02:14,160 the value of the currentBook property should probably just be null. 49 00:02:14,160 --> 00:02:16,750 We can set that directly inside the constructor method 50 00:02:16,750 --> 00:02:18,720 without passing in a value. 51 00:02:18,720 --> 00:02:22,760 Later on, when a patron does borrow a book, the checkOut method can update 52 00:02:22,760 --> 00:02:26,860 the current book property so it holds the book that the patron is borrowing. 53 00:02:26,860 --> 00:02:30,850 Let's add these constructor methods to our class files, then afterwards we can create 54 00:02:30,850 --> 00:02:34,614 some test objects and see what they look like and how they work so far. 55 00:02:34,614 --> 00:02:38,154 Head to the attached work space to see the updated read me with new instructions. 56 00:02:38,154 --> 00:02:41,114 Or see the teachers notes attached to this video. 57 00:02:41,114 --> 00:02:41,924 Once you're finished or 58 00:02:41,924 --> 00:02:44,584 if you're having trouble, check out the solution following this video.