1 00:00:01,640 --> 00:00:07,580 Let's start with the interface that is basically the base of this this pattern, so we can see that 2 00:00:07,940 --> 00:00:12,080 we have this computer interface with a single method to compute. 3 00:00:12,620 --> 00:00:20,630 And the three objects, the three concrete objects that will implement this interface will implement 4 00:00:20,630 --> 00:00:28,220 this method as well, of course, but the implementation will be slightly different for each and every 5 00:00:28,220 --> 00:00:28,430 one. 6 00:00:28,970 --> 00:00:37,820 So for the first one, for the laptop class, we will print laptop computers for phone, phone computers 7 00:00:37,820 --> 00:00:39,140 and for smart TV. 8 00:00:39,140 --> 00:00:44,240 You will have this result in the console alongside. 9 00:00:44,240 --> 00:00:51,380 We have the computer factory, which will have basically get the computer method that will return the 10 00:00:51,390 --> 00:00:53,330 type of computer that we want to create. 11 00:00:53,840 --> 00:01:04,490 So if we apply in this method, a laptop as well as the computer that we want to create, then this 12 00:01:04,700 --> 00:01:12,020 statement will be will be executed and a new chapter will be returned and so on and so forth for the 13 00:01:12,020 --> 00:01:22,340 rest of the objects that we can create in this factory class, in this computer factory class, if we 14 00:01:22,340 --> 00:01:28,340 will supply an unknown parameter, the factory will return. 15 00:01:28,550 --> 00:01:30,070 No, of course you will. 16 00:01:30,440 --> 00:01:31,730 You can change this. 17 00:01:31,730 --> 00:01:32,960 You can change its behavior. 18 00:01:32,960 --> 00:01:34,700 We can put switchgear statements. 19 00:01:34,700 --> 00:01:36,000 You can put whatever you want. 20 00:01:36,000 --> 00:01:37,810 But also you can treat this case as well. 21 00:01:37,820 --> 00:01:42,280 We can have a default computer that you may want to return. 22 00:01:42,440 --> 00:01:50,270 But for the sake of simplicity, let's stick with with this and in this class, do you see the factory 23 00:01:50,270 --> 00:01:51,320 pattern in action? 24 00:01:51,800 --> 00:01:59,810 You need to create first a computer factory, of course, and then we can create this type of object, 25 00:01:59,810 --> 00:02:02,390 but we won't initialize it because it's an interface. 26 00:02:02,900 --> 00:02:10,240 And we can we can invoke the computer factory object to get a letter for us. 27 00:02:10,250 --> 00:02:14,330 And now the computer object will be equal to a laptop. 28 00:02:14,750 --> 00:02:23,930 Then we do the same with different objects, of course, for the rest of the computers here for phone 29 00:02:23,930 --> 00:02:24,770 and smart TV. 30 00:02:25,280 --> 00:02:33,560 So basically you will see in the console laptop computers, phone computers, multiple countries. 31 00:02:33,560 --> 00:02:34,880 But let's see this in action. 32 00:02:34,880 --> 00:02:38,510 Actually, let's let's execute this code. 33 00:02:38,810 --> 00:02:41,820 And you can see we have the expected output here. 34 00:02:42,410 --> 00:02:43,810 So this is how it works. 35 00:02:43,820 --> 00:02:52,700 It's a bit it can be a bit daunting to create a factory pattern because, of course, this is an overly 36 00:02:52,700 --> 00:02:53,840 simplified example. 37 00:02:53,840 --> 00:03:02,330 But if you will have a much more complex structure of objects, then it will be a bit difficult. 38 00:03:02,930 --> 00:03:06,210 And also you will need to think about this from the beginning. 39 00:03:06,230 --> 00:03:11,020 So this is actually a decision that needs to be made before you start coding. 40 00:03:11,930 --> 00:03:13,940 So that's it for the factory. 41 00:03:13,950 --> 00:03:18,490 Better join me in the next iteration where we are going to discuss about Singleton pattern.