1 00:00:00,000 --> 00:00:04,939 [MUSIC] 2 00:00:04,939 --> 00:00:06,970 Welcome, I'm Alena. 3 00:00:06,970 --> 00:00:11,240 In this course we'll be extending from the knowledge learned in a previous course 4 00:00:11,240 --> 00:00:14,360 to look at additional relationships in the structure on our code. 5 00:00:15,480 --> 00:00:18,790 Laziness is one of the great virtues of a programmer, 6 00:00:18,790 --> 00:00:22,590 we don't want to write the same code over and over again. 7 00:00:22,590 --> 00:00:26,510 This is why one of the core concepts of object oriented programming 8 00:00:26,510 --> 00:00:31,580 is aimed directly at reducing the amount of repetition that you have to do. 9 00:00:31,580 --> 00:00:32,830 It's called inheritance. 10 00:00:34,020 --> 00:00:36,990 At its simplest, it means we can give a child or 11 00:00:36,990 --> 00:00:42,520 a subclass all the abilities and attributes of a parent or superclass. 12 00:00:42,520 --> 00:00:45,871 This helps us to greatly reduce the amount of code we need to write. 13 00:00:47,160 --> 00:00:49,640 Let's take these elephants for example. 14 00:00:49,640 --> 00:00:54,140 Each of these elephants could be an instance of an elephant class. 15 00:00:54,140 --> 00:00:58,930 Each object would simply set specific properties such as color and logo. 16 00:00:59,980 --> 00:01:03,890 Both are created using the same pattern or class. 17 00:01:03,890 --> 00:01:05,840 But what happens when we want to build a mammoth? 18 00:01:07,220 --> 00:01:11,020 Not only have we changed the type of material that's used, but 19 00:01:11,020 --> 00:01:12,390 we've also added tusks. 20 00:01:13,610 --> 00:01:19,120 Continuing to modify the original pattern to add more features, can get complicated, 21 00:01:19,120 --> 00:01:23,450 and make it more difficult to create our simple base elephant. 22 00:01:23,450 --> 00:01:26,770 Then what happens when we want to add additional designs? 23 00:01:26,770 --> 00:01:29,140 Such as an Elvis elephant. 24 00:01:29,140 --> 00:01:32,910 Instead, we can keep our original pattern in our class, and 25 00:01:32,910 --> 00:01:37,680 then extend that class by creating a child, or sub-class, which 26 00:01:37,680 --> 00:01:42,200 includes all the attributes of the parent, while additionally adding features. 27 00:01:43,400 --> 00:01:46,240 As another example let's take a bike. 28 00:01:46,240 --> 00:01:51,500 We have properties such as frame color, number of gears, and current speed. 29 00:01:51,500 --> 00:01:55,820 We also have methods that control things such as brake, change speed, and 30 00:01:55,820 --> 00:01:56,430 change gears. 31 00:01:57,470 --> 00:02:00,600 Now let's say we want to build an electric bike. 32 00:02:00,600 --> 00:02:05,900 An electric bike is a regular bike with the addition of an electric drive system. 33 00:02:05,900 --> 00:02:08,990 We would need additional properties for battery and 34 00:02:08,990 --> 00:02:13,810 motor and a method to control the power such as change_power. 35 00:02:13,810 --> 00:02:18,530 Instead of adding these properties and methods to the bike class we could create 36 00:02:18,530 --> 00:02:23,820 a child class named electric bike, that extends the original bike class 37 00:02:23,820 --> 00:02:27,190 by giving the child access to all the original properties and 38 00:02:27,190 --> 00:02:30,930 methods while allowing the child to add these additional features. 39 00:02:32,100 --> 00:02:36,855 In this course, we'll write code to extend a simple directory project. 40 00:02:36,855 --> 00:02:40,285 If you would like to practice building the original directory, or 41 00:02:40,285 --> 00:02:43,865 would like a refresher of things that are not covered in this course, 42 00:02:43,865 --> 00:02:46,765 please check the notes associated with this video. 43 00:02:46,765 --> 00:02:47,895 Let's take a look at the project. 44 00:02:49,055 --> 00:02:53,170 The simple directory we'll be starting with has a list of PHP Conferences 45 00:02:53,170 --> 00:02:56,280 with links to their website, email, and twitter. 46 00:02:56,280 --> 00:03:01,460 We have the ability to edit and deactivate a listing. 47 00:03:03,100 --> 00:03:05,532 We also have the ability to add a new listing. 48 00:03:05,532 --> 00:03:11,210 ll We'be adding premium listings which include a description and 49 00:03:11,210 --> 00:03:14,340 featured listings which also include a code of conduct. 50 00:03:15,740 --> 00:03:20,070 These new listing types will be used on the listing page, and also for the forms. 51 00:03:21,210 --> 00:03:25,836 Along with these features, we'll also add additional styling and navigation.