1 00:00:00,540 --> 00:00:05,460 To add data to a class we use properties or class specific variables. 2 00:00:05,460 --> 00:00:10,650 These work exactly like any other variable except that they belong to the object, 3 00:00:10,650 --> 00:00:14,900 and therefore can only be accessed using the object. 4 00:00:14,900 --> 00:00:20,530 When declaring a property, the visibility must be defined by an access modifier. 5 00:00:20,530 --> 00:00:24,210 These access modifiers are public, private, or protected. 6 00:00:24,210 --> 00:00:30,060 The access modifiers allow us to control access to our properties. 7 00:00:30,060 --> 00:00:34,190 We'll demonstrate how visibility affects our properties a little later. 8 00:00:34,190 --> 00:00:36,290 For now, we'll use public. 9 00:00:36,290 --> 00:00:38,590 Let's add the properties for our recipe class. 10 00:00:40,050 --> 00:00:43,450 We put the public keyword in front of a class property. 11 00:00:43,450 --> 00:00:47,390 The naming convention for properties is camelCase. 12 00:00:48,540 --> 00:00:51,470 Like a camel the humps are in the middle. 13 00:00:51,470 --> 00:00:53,970 The name starts with the lower case letter and 14 00:00:53,970 --> 00:00:56,238 all other words start with a capital letter. 15 00:00:56,238 --> 00:01:00,736 For example, $ingredients. 16 00:01:00,736 --> 00:01:07,660 Or $dryIngredients. 17 00:01:07,660 --> 00:01:11,930 For this project, we're just going to use a single ingredients property. 18 00:01:13,040 --> 00:01:17,190 We can create a property with or without a default value. 19 00:01:17,190 --> 00:01:22,010 For example, we can create a property for source so 20 00:01:22,010 --> 00:01:23,980 that we know where this recipe came from. 21 00:01:25,390 --> 00:01:28,602 By default these are going to be my own recipes, so 22 00:01:28,602 --> 00:01:31,670 I can set the default source to Alena Holligan. 23 00:01:34,269 --> 00:01:38,410 In contrast, we want each recipe to have its own title. 24 00:01:39,860 --> 00:01:41,750 So we can create a title property. 25 00:01:44,790 --> 00:01:47,530 Our title property would not have a default value. 26 00:01:49,220 --> 00:01:53,120 We can also initialize a property like any other variable. 27 00:01:53,120 --> 00:01:55,500 By initializing ingredients 28 00:01:55,500 --> 00:02:01,240 with an empty array, we make our class easier to read and 29 00:02:01,240 --> 00:02:05,010 we know right up front that our ingredients will be stored in an array. 30 00:02:06,610 --> 00:02:08,400 We have a few more properties to add. 31 00:02:11,700 --> 00:02:13,220 We want to add instructions. 32 00:02:16,170 --> 00:02:21,160 We'll make those an array as well, then we'll 33 00:02:21,160 --> 00:02:26,280 add yield without a default value. 34 00:02:27,910 --> 00:02:31,530 Finally, most cookbooks are organized in some way, 35 00:02:31,530 --> 00:02:36,360 usually by category but we could really group these any way we want. 36 00:02:36,360 --> 00:02:38,690 Let's add a generic property called tag. 37 00:02:43,791 --> 00:02:46,150 We'll initialize this as an array, as well. 38 00:02:47,180 --> 00:02:48,960 Now that we have our properties set up. 39 00:02:48,960 --> 00:02:51,560 We're ready to start accessing those properties and 40 00:02:51,560 --> 00:02:53,420 creating independent objects 41 00:02:53,420 --> 00:02:56,260 that can each have different values, for those properties.