1 00:00:00,840 --> 00:00:04,090 This is a way of how to implement the observable pattern in your code. 2 00:00:04,590 --> 00:00:11,160 Basically, you need to have either an abstract class or an interface in a defined in your code for 3 00:00:11,160 --> 00:00:15,360 the object will abstract object here. 4 00:00:16,050 --> 00:00:21,780 You will need to use Generex because it's better not to have a specific object here. 5 00:00:22,570 --> 00:00:28,710 You maybe will need to refactor your object to create another type of object. 6 00:00:29,280 --> 00:00:31,410 So it's better to to define it. 7 00:00:31,770 --> 00:00:39,070 Using Generex also, you will need to have either a Hashmat or a hash table to story or objects and 8 00:00:39,070 --> 00:00:40,580 the status for each of them. 9 00:00:41,490 --> 00:00:47,700 Maybe if you will check out an object, you'll not need the object anymore. 10 00:00:47,880 --> 00:00:55,410 You'll be needing to to store this object in this hash table or Hashmat and put it a billion value or 11 00:00:55,440 --> 00:01:00,330 whatever, whatever value you will mark your object with. 12 00:01:00,540 --> 00:01:08,940 Just you, you know, make it unavailable to make it checked out for for you or for your program not 13 00:01:08,940 --> 00:01:10,350 to use that specific object. 14 00:01:11,310 --> 00:01:17,310 Hash table or hash maps are preferred because of their performance of receiving data of retrieving the 15 00:01:17,310 --> 00:01:17,800 objects. 16 00:01:18,090 --> 00:01:20,550 So this is the way to go. 17 00:01:21,090 --> 00:01:24,870 Also, there is the create method here, which needs to be abstract. 18 00:01:24,870 --> 00:01:33,600 You will need to implement your own method and object to a concrete object, concrete class. 19 00:01:34,530 --> 00:01:40,080 So this you'll find less articles and explanations on how to get them out. 20 00:01:40,080 --> 00:01:46,110 And especially if you compare this chapter, which are more popular, if you will just put your object 21 00:01:46,110 --> 00:01:50,540 in the hash table that we define here with the status of force. 22 00:01:50,760 --> 00:01:56,220 So this object will be marked as not available for your program. 23 00:01:57,300 --> 00:02:05,280 And but of course, you you can define your own method to put these objects back into production. 24 00:02:05,280 --> 00:02:10,860 So that's not a limitation of of this pattern. 25 00:02:11,190 --> 00:02:18,600 And also for checking in, you will just search for your hash table here in your hash table. 26 00:02:18,870 --> 00:02:25,330 You will search for an object that has a status positive, that has a status through. 27 00:02:25,650 --> 00:02:30,080 So this object will be returned, otherwise no will be returned. 28 00:02:30,300 --> 00:02:31,970 But this is just for simplicity. 29 00:02:31,980 --> 00:02:42,720 You can have any any anything here, any type of object that you may be returning a basic T object if 30 00:02:42,720 --> 00:02:43,250 you want to. 31 00:02:43,860 --> 00:02:50,820 Also, you can see the synchronous keyword has been used for both methods because as I said, this object 32 00:02:51,000 --> 00:02:57,240 pattern can be can cause some problems in terms of multi threading. 33 00:02:57,240 --> 00:03:04,290 So if you're using if your program is running in a multi trading environment, if you're performing 34 00:03:04,290 --> 00:03:12,040 several tasks at once, you may have some problems when checking in and out specific objects. 35 00:03:12,660 --> 00:03:17,460 This is the robot's pool class that will extend the object pool. 36 00:03:17,460 --> 00:03:24,290 So I'll be using the robot's class that I define in a previous Loreal. 37 00:03:24,690 --> 00:03:26,520 And here we have to create. 38 00:03:26,850 --> 00:03:34,710 As you can see, the great method will assign I will create a new robot, will assign a random ID here, 39 00:03:34,980 --> 00:03:40,170 will create an empty array list and an empty set of components. 40 00:03:40,770 --> 00:03:43,860 The array list was for the features of the robot. 41 00:03:44,430 --> 00:03:51,120 We may not know at the creation time what will what the features for the robot will be. 42 00:03:51,360 --> 00:03:59,130 So it's better to create some imperialist and empty components, whatever, whatever properties your 43 00:03:59,130 --> 00:04:07,260 class have, because then at the wrong time you may need to populate those those properties. 44 00:04:07,260 --> 00:04:15,280 But at the beginning you just created the object and then the program will handle the details for or 45 00:04:15,310 --> 00:04:16,640 for this particular object. 46 00:04:18,270 --> 00:04:21,510 I will recap a bit the robot class as well. 47 00:04:21,960 --> 00:04:24,930 You can see there are only three properties here. 48 00:04:24,930 --> 00:04:34,380 A constructor try to mimic more complex object by putting a more complex constructor with more than 49 00:04:34,380 --> 00:04:40,800 two properties and also gethers in setters for each and every one, the colonial. 50 00:04:41,190 --> 00:04:44,910 However, the implementation of the control interface is not needed anymore. 51 00:04:44,910 --> 00:04:52,740 So this is the only difference in this code between this tutorial and the previous one. 52 00:04:52,980 --> 00:04:55,530 And the components class hasn't been changed. 53 00:04:55,530 --> 00:05:00,180 So basically we have two strings, two properties, name and functionality and get. 54 00:05:00,390 --> 00:05:01,740 And there's for each of them. 55 00:05:02,100 --> 00:05:10,770 And as you can see in the app class, we just create a new robot ball and we create our first robot 56 00:05:10,770 --> 00:05:15,450 by calling the create method from inside the robot pool. 57 00:05:15,780 --> 00:05:19,410 And the second robot will be created using the same method. 58 00:05:19,410 --> 00:05:26,910 But however, we do some some tasks here between these lines and we decide that we need to decommission 59 00:05:26,910 --> 00:05:27,800 our first robot. 60 00:05:28,050 --> 00:05:35,730 So what we need to do is to check this out, to call the check out method. 61 00:05:35,850 --> 00:05:41,020 And as a as an argument, we will supply the name of the object that we want to check out. 62 00:05:41,520 --> 00:05:45,480 This is pretty straightforward and this is also available. 63 00:05:46,600 --> 00:05:48,860 So we're checking in a new a new robot. 64 00:05:49,290 --> 00:05:55,720 This will be the checking method will be called and a new robot will be returned as the third robot. 65 00:05:56,130 --> 00:05:58,470 So this is kind of it. 66 00:05:59,400 --> 00:06:00,570 It's pretty. 67 00:06:00,570 --> 00:06:01,980 It's pretty complex. 68 00:06:03,150 --> 00:06:05,160 This is an overly simplified example. 69 00:06:05,160 --> 00:06:14,520 But things in real life tend to be very complex and use case for this might be when you will you need 70 00:06:14,520 --> 00:06:20,690 to maybe to connect to a specific database and you might need an object for that. 71 00:06:20,730 --> 00:06:28,950 You may need an object for creating a data connection to my school or a school or whatever your database 72 00:06:28,950 --> 00:06:29,880 provider is. 73 00:06:31,350 --> 00:06:34,730 And an object can be used for that. 74 00:06:34,740 --> 00:06:43,590 But as I said in the previous video, it's better to have a single tone object for for the pool. 75 00:06:43,860 --> 00:06:54,330 And also you may need to apply a design pattern to the create method as well for, you know, just making 76 00:06:54,330 --> 00:06:59,090 things more intuitive when reading the code. 77 00:06:59,340 --> 00:07:03,890 So you may apply a factory or a builder pattern for or for a discrete method. 78 00:07:03,900 --> 00:07:09,660 But as I said, this is a very simplified example here. 79 00:07:10,020 --> 00:07:14,640 So we won't use we won't make this more complicated than it is. 80 00:07:15,880 --> 00:07:16,920 That's kind of it. 81 00:07:17,180 --> 00:07:23,010 So join me in the next tutorial where we are going to discuss about the structural design patterns. 82 00:07:23,310 --> 00:07:24,960 So see you in the next, Loreal.