1 00:00:00,190 --> 00:00:05,330 Before we leave this display recipe method I want to look at one more thing. 2 00:00:05,330 --> 00:00:09,770 Whenever you have a loop in a method, it's a good place to evaluate 3 00:00:09,770 --> 00:00:13,850 if there's something that could be moved to its own method. 4 00:00:13,850 --> 00:00:18,980 Listing our ingredients seems like something that we could use elsewhere and 5 00:00:18,980 --> 00:00:22,020 it would benefit from being in its own method. 6 00:00:22,020 --> 00:00:23,430 So let's go to the top of this class. 7 00:00:25,830 --> 00:00:34,188 And we'll create a new public static function, listIngredients. 8 00:00:38,117 --> 00:00:41,178 We'll pass in an associative array of ingredients. 9 00:00:44,287 --> 00:00:50,620 Then we can initialize our output, and return the output. 10 00:00:54,830 --> 00:00:57,910 Now we can copy the foreach loop from our display recipe. 11 00:01:05,746 --> 00:01:10,492 We'll change the array to the ingredients array that this method is accepting. 12 00:01:12,761 --> 00:01:16,988 Now we need to modify our display recipe method to call this new method. 13 00:01:22,238 --> 00:01:24,864 Instead of using the keyword this, 14 00:01:24,864 --> 00:01:30,740 we use self with double colons to call another static method within this class. 15 00:01:32,860 --> 00:01:36,768 We then pass the recipe ingredients to the method. 16 00:01:44,061 --> 00:01:45,769 Let's run our script again. 17 00:01:48,251 --> 00:01:50,861 We see the recipe exactly like we did before, but 18 00:01:50,861 --> 00:01:54,440 this time the list of ingredients is coming from its own method. 19 00:01:55,600 --> 00:02:00,250 You're doing a wonderful job and learning a lot, let's review. 20 00:02:00,250 --> 00:02:04,730 A class is a way to group your data and functionality together. 21 00:02:05,740 --> 00:02:11,300 An object allows that data to persist throughout your script. 22 00:02:11,300 --> 00:02:14,230 If you're doing more than one thing with that data, 23 00:02:14,230 --> 00:02:17,370 you'll probably be creating an object. 24 00:02:17,370 --> 00:02:22,760 We can also use a class to group functionality without storing information. 25 00:02:22,760 --> 00:02:26,240 You can access this functionality using a static method. 26 00:02:27,480 --> 00:02:33,420 A static method can accept data, perform its function, and return the results. 27 00:02:33,420 --> 00:02:38,140 But it doesn't store anything after the method is run. 28 00:02:38,140 --> 00:02:41,700 Now that we have all the basics of your class set up, are you ready for 29 00:02:41,700 --> 00:02:42,320 some magic?