1 00:00:02,000 --> 00:00:09,220 Do you understand classes, let's understand object oriented programming now, depending on your level 2 00:00:09,220 --> 00:00:15,040 of knowledge and if you worked with modern JavaScript, that maybe also some other programming languages, 3 00:00:15,400 --> 00:00:21,940 you might be aware of what Claus's hardware for and what OPIS object oriented programming is all about. 4 00:00:22,300 --> 00:00:27,190 So Darfor, you can also skipped his lecture to jump right ahead to the part where we write code. 5 00:00:27,760 --> 00:00:31,570 Otherwise, definitely stick with me because it is important to understand this. 6 00:00:32,260 --> 00:00:38,080 The idea behind object oriented programming and classes will be important for that, as you will see, 7 00:00:38,620 --> 00:00:42,230 is that you work with real life entities in your code. 8 00:00:42,250 --> 00:00:43,330 You could say so. 9 00:00:43,330 --> 00:00:51,550 Did you work with things in your code with objects that resemble real life objects as far as possible, 10 00:00:51,550 --> 00:00:55,990 at least to make it easier for you as a developer to reason about your code? 11 00:00:56,290 --> 00:01:01,000 For example, we might be building an online shop and there we might have a product list. 12 00:01:01,330 --> 00:01:07,240 We might want to work with a product list, object data for which has everything we need to manage a 13 00:01:07,240 --> 00:01:07,980 product list. 14 00:01:08,190 --> 00:01:11,410 A method to add products to the lead products. 15 00:01:11,620 --> 00:01:12,790 The list itself. 16 00:01:13,390 --> 00:01:18,610 So for example, this might be an object that is responsible for rendering a list of products and for 17 00:01:18,610 --> 00:01:22,390 managing it, which were fetched from a service, from a database. 18 00:01:22,870 --> 00:01:26,530 So this product holds all the rendering and fetching and management logic. 19 00:01:27,280 --> 00:01:32,380 Now that's a product list in our program into Web site we're building. 20 00:01:32,560 --> 00:01:37,870 We might also need to work with the individual product, though, so we might all the one that object 21 00:01:37,900 --> 00:01:43,750 or multiple objects, one for each product that is responsible for managing this single product. 22 00:01:43,990 --> 00:01:49,550 It might hold and render the details about that product, maybe allow us to add it to a cart. 23 00:01:49,870 --> 00:01:50,830 Things like debt. 24 00:01:51,310 --> 00:01:57,250 So when we want to draw a user interface to the screen, we want to manage that through JavaScript and 25 00:01:57,300 --> 00:01:58,450 deafer for typescript. 26 00:01:58,780 --> 00:02:04,120 Then we could implement it with a product list and a product object which hold the logic for managing 27 00:02:04,120 --> 00:02:07,660 the underlying data, but all for rendering the content on the screen. 28 00:02:07,960 --> 00:02:11,500 And of course, Stanford, these two objects would kind of be related. 29 00:02:11,980 --> 00:02:16,940 We might also have a shopping cart object on our screen, which is responsible for rendering and managing 30 00:02:16,940 --> 00:02:17,920 the shopping cart. 31 00:02:18,100 --> 00:02:23,620 It's of course, also connected to the product and therefore it holds all the logic we need to render 32 00:02:23,620 --> 00:02:27,880 our shopping cart, placing orders and communicating with the server and so on. 33 00:02:27,970 --> 00:02:33,610 So that would be one way of how we could think about the applications we're building, how we could 34 00:02:33,610 --> 00:02:35,560 split it into logical pieces. 35 00:02:35,590 --> 00:02:42,100 That makes sense to us as humans and encode in typescript and JavaScript in most modern programming 36 00:02:42,100 --> 00:02:42,700 languages. 37 00:02:42,930 --> 00:02:49,270 Does this actively supported because we have objects which are more complex data structures that hold 38 00:02:49,270 --> 00:02:50,620 properties and methods. 39 00:02:50,680 --> 00:02:52,870 And of course we do have that in JavaScript as well. 40 00:02:53,350 --> 00:02:56,560 But we might also have classes that help us with that. 41 00:02:57,340 --> 00:03:00,550 Now, what's the idea behind classes and what are incenses? 42 00:03:00,790 --> 00:03:05,710 Well, we've got these objects and when following does object oriented approach, we could consider 43 00:03:05,710 --> 00:03:13,150 splitting our app or our application logic into such objects which manage parts of our logic. 44 00:03:13,810 --> 00:03:19,960 Now, connected to the idea of using these objects, which of course do exist in JavaScript, we can 45 00:03:19,960 --> 00:03:20,610 use objects. 46 00:03:20,620 --> 00:03:23,110 There is the idea of having classes. 47 00:03:23,980 --> 00:03:27,400 Objects are the concrete things we work with in our code. 48 00:03:27,520 --> 00:03:35,530 The data structures we use to store data, to store methods to execute methods on classes are blueprints 49 00:03:35,590 --> 00:03:36,400 for objects. 50 00:03:36,580 --> 00:03:42,220 Classes allow us to define how objects should look like, which data they should hold. 51 00:03:42,250 --> 00:03:48,020 Which methods they should have so that we can easily build objects based on these classes. 52 00:03:48,310 --> 00:03:51,790 And we then called this instances off the classes. 53 00:03:51,850 --> 00:03:54,850 So an object then is an instance of a class. 54 00:03:54,880 --> 00:04:01,060 If it's based on such a class so that we can quickly replicate multiple objects with the same structure, 55 00:04:01,090 --> 00:04:03,940 the same methods based on the same classes. 56 00:04:04,150 --> 00:04:09,250 So classes help us define how objects should look like, which properties and methods to have and so 57 00:04:09,250 --> 00:04:09,580 on. 58 00:04:10,210 --> 00:04:17,740 So classes exist to speed up the creation of objects and it's simply an alternative to using the object. 59 00:04:17,770 --> 00:04:19,540 Literal notation, you already know. 60 00:04:20,110 --> 00:04:21,320 They simply make it easier. 61 00:04:21,340 --> 00:04:27,040 Classes simply make it easier to create multiple objects, which generally have the same structure and 62 00:04:27,040 --> 00:04:32,590 the same efforts, which might only defriended exact data details which are stored in there. 63 00:04:32,830 --> 00:04:36,460 Let's say we have multiple persons we want to represent with objects. 64 00:04:36,730 --> 00:04:40,780 While each person might have a name and a H, the values will differ. 65 00:04:40,870 --> 00:04:42,640 The general structure is the same. 66 00:04:43,360 --> 00:04:44,410 So that's the theory. 67 00:04:44,560 --> 00:04:45,980 Let's see it in practice.