1 00:00:00,000 --> 00:00:04,884 [MUSIC] 2 00:00:04,884 --> 00:00:08,870 So far, we've built a single parent with a single child. 3 00:00:08,870 --> 00:00:14,550 This child was able to share and override the functionality of the parent, 4 00:00:14,550 --> 00:00:18,870 allowing us to reduce the amount of repetition in our code. 5 00:00:18,870 --> 00:00:20,480 But we don't need to stop there. 6 00:00:21,630 --> 00:00:26,930 We can create as many children as we want, and each of these children will inherit 7 00:00:26,930 --> 00:00:31,050 all of the abilities and attributes of the parent class. 8 00:00:31,050 --> 00:00:34,950 However, they will not have any of the added abilities and 9 00:00:34,950 --> 00:00:37,400 features of the other children. 10 00:00:37,400 --> 00:00:41,700 This is called a Sibling Relationship, because both classes have the same parent. 11 00:00:42,850 --> 00:00:45,510 You could of course add the same features to another child, 12 00:00:45,510 --> 00:00:48,020 but there's a better way. 13 00:00:48,020 --> 00:00:52,150 When you want to create a new class that has all the abilities and 14 00:00:52,150 --> 00:00:55,960 attributes of a child, as well as the parent, 15 00:00:55,960 --> 00:00:59,640 child classes can be extended further to create grandchildren. 16 00:01:00,710 --> 00:01:04,940 You may continue to add children for an infinite number of generations. 17 00:01:04,940 --> 00:01:08,190 Each subsequent generation gaining the attributes and 18 00:01:08,190 --> 00:01:11,340 actions of all generations before. 19 00:01:11,340 --> 00:01:16,600 The only limitation is that you may only extend from one parent at a time. 20 00:01:16,600 --> 00:01:18,860 Let's go back to our code and see this in action. 21 00:01:20,080 --> 00:01:22,199 Let's create a second child of ListingBasic. 22 00:01:25,236 --> 00:01:27,834 We'll call this ListingInactive. 23 00:01:38,692 --> 00:01:44,036 And we'll extend, ListingBasic. 24 00:01:47,665 --> 00:01:51,370 This will be a sibling of ListingPremium. 25 00:01:51,370 --> 00:01:56,650 Without adding any code, this class will have all the abilities and attributes of 26 00:01:56,650 --> 00:02:02,480 ListingBasic, and can be swapped out for that parent class just like we did before. 27 00:02:02,480 --> 00:02:06,700 However, this class will not know about the description feature, so 28 00:02:06,700 --> 00:02:09,530 we will not be able to use that functionality. 29 00:02:09,530 --> 00:02:11,641 Let's include this new class in our config, 30 00:02:22,157 --> 00:02:26,548 Now we can switch out our test object to use the ListingInactive. 31 00:02:26,548 --> 00:02:28,468 Open index.php. 32 00:02:38,089 --> 00:02:40,600 Now let's preview this in a browser. 33 00:02:40,600 --> 00:02:44,480 Because we're passing the description into our construct, 34 00:02:44,480 --> 00:02:49,320 it just ignores the description, because ListingInactive does not use that. 35 00:02:49,320 --> 00:02:51,320 Let's go back and create another class. 36 00:02:51,320 --> 00:02:53,700 This one will be a child of ListingPremium. 37 00:02:55,950 --> 00:02:57,763 We'll call this ListingFeatured, 38 00:03:07,636 --> 00:03:11,903 And it extends ListingPremium. 39 00:03:17,374 --> 00:03:20,806 This class will inherit all the abilities and 40 00:03:20,806 --> 00:03:27,325 attributes of not only the ListingPremium, but also the ListingBasic. 41 00:03:27,325 --> 00:03:29,604 Once more, we need to include this class in our config. 42 00:03:36,382 --> 00:03:38,166 Now we can add another test. 43 00:03:49,918 --> 00:03:51,674 Now let's preview in the browser. 44 00:03:54,077 --> 00:03:57,267 Let's view the page source and increase the font size. 45 00:04:02,886 --> 00:04:07,264 Even though ListingFeatured doesn't have the set description methods or 46 00:04:07,264 --> 00:04:11,720 attributes defined, it is using the inherited behaviors and attributes.