1 00:00:00,780 --> 00:00:02,280 Okay, so we are almost done. 2 00:00:02,280 --> 00:00:06,100 We've now got this great report that we know works, but 3 00:00:06,100 --> 00:00:09,500 it only works for items that are in stock. 4 00:00:10,820 --> 00:00:15,230 So let's go ahead and make one for items that are out of stock too. 5 00:00:16,580 --> 00:00:21,710 Now what I could do is take this in stock report and copy it. 6 00:00:21,710 --> 00:00:25,945 And paste it and change it to out_of_stock_report. 7 00:00:28,995 --> 00:00:33,067 And then we just say we want the instances that are not in stock, and 8 00:00:33,067 --> 00:00:35,420 this would work if we did it right now. 9 00:00:35,420 --> 00:00:39,920 We could say Shirt.out_of_stock_report. 10 00:00:40,980 --> 00:00:46,080 And if we run that, we've 11 00:00:46,080 --> 00:00:49,950 got this out of stock report that lists items that are out of stock. 12 00:00:51,220 --> 00:00:54,180 But you'll notice up here we're gonna have a lot of 13 00:00:54,180 --> 00:00:56,780 duplicated code between these two. 14 00:00:56,780 --> 00:01:01,500 So let's go ahead and extract that to its own method. 15 00:01:01,500 --> 00:01:03,630 And this looks like a great place to start. 16 00:01:03,630 --> 00:01:06,925 It looks like we have a lot of common things between these two methods. 17 00:01:06,925 --> 00:01:10,530 All that's different is the title of the report, and 18 00:01:10,530 --> 00:01:12,400 the items that are going inside of it. 19 00:01:13,700 --> 00:01:16,770 So let's go ahead and create a method called report. 20 00:01:18,040 --> 00:01:21,035 And it'll take a title and items. 21 00:01:21,035 --> 00:01:27,057 [SOUND] So now, we can grab this, 22 00:01:27,057 --> 00:01:34,204 cut it, and we can just paste it here. 23 00:01:34,204 --> 00:01:38,440 Then we change reportable to items, and we will print the title. 24 00:01:39,930 --> 00:01:42,250 And we should be good to go at this point. 25 00:01:42,250 --> 00:01:47,194 We would say title is the in stock report, and 26 00:01:47,194 --> 00:01:52,136 then we just call the method with the title and 27 00:01:52,136 --> 00:01:55,794 the items that we have selected. 28 00:01:58,396 --> 00:01:59,559 And we can do the same thing here. 29 00:02:11,750 --> 00:02:17,608 So now if we run this, we see absolutely no change, 30 00:02:17,608 --> 00:02:21,440 which is exactly what we wanted. 31 00:02:23,220 --> 00:02:29,060 Now, the benefit to something like this is if we wanted to change something for 32 00:02:29,060 --> 00:02:33,030 both of these reports at some point, maybe we want to 33 00:02:34,370 --> 00:02:38,945 print this character, 50 times at the top and the bottom of the report. 34 00:02:38,945 --> 00:02:44,021 [SOUND] Well now we only have 35 00:02:44,021 --> 00:02:48,644 to do that in one place. 36 00:02:48,644 --> 00:02:54,390 And all of our reports would get the benefit of just changing that one method. 37 00:02:57,300 --> 00:03:03,270 So the last thing that we're gonna do here is name space our shirts and 38 00:03:03,270 --> 00:03:08,170 pants and we're going to put this all inside of a Treehouse module. 39 00:03:08,170 --> 00:03:11,970 So, in case for some reason we are ever 40 00:03:11,970 --> 00:03:16,700 working in an application where we have shirts, pants and accessories. 41 00:03:16,700 --> 00:03:20,512 Well we're not going to clash with that name space. 42 00:03:20,512 --> 00:03:22,554 [SOUND] 43 00:03:32,260 --> 00:03:33,001 So there we go, 44 00:03:33,001 --> 00:03:34,490 we indent it just a little bit. 45 00:03:37,081 --> 00:03:42,820 And now all we have to do is change this instance to say Treehouse Shirt. 46 00:03:58,862 --> 00:04:03,021 And the same thing with the pants and accessories. 47 00:04:10,658 --> 00:04:15,154 And now, if we're ever in the situation where we are working with 48 00:04:15,154 --> 00:04:19,406 another library or other classes that are shirts, pants, or 49 00:04:19,406 --> 00:04:23,290 accessories, we are not going to stomp all over them. 50 00:04:23,290 --> 00:04:25,560 Everything will be neatly contained. 51 00:04:25,560 --> 00:04:27,330 In our Treehouse name space. 52 00:04:28,700 --> 00:04:29,580 Great work, everybody.