This is a way of how to implement the observable pattern in your code.
Basically, you need to have either an abstract class or an interface in a defined in your code for
the object will abstract object here.
You will need to use Generex because it's better not to have a specific object here.
You maybe will need to refactor your object to create another type of object.
So it's better to to define it.
Using Generex also, you will need to have either a Hashmat or a hash table to story or objects and
the status for each of them.
Maybe if you will check out an object, you'll not need the object anymore.
You'll be needing to to store this object in this hash table or Hashmat and put it a billion value or
whatever, whatever value you will mark your object with.
Just you, you know, make it unavailable to make it checked out for for you or for your program not
to use that specific object.
Hash table or hash maps are preferred because of their performance of receiving data of retrieving the
objects.
So this is the way to go.
Also, there is the create method here, which needs to be abstract.
You will need to implement your own method and object to a concrete object, concrete class.
So this you'll find less articles and explanations on how to get them out.
And especially if you compare this chapter, which are more popular, if you will just put your object
in the hash table that we define here with the status of force.
So this object will be marked as not available for your program.
And but of course, you you can define your own method to put these objects back into production.
So that's not a limitation of of this pattern.
And also for checking in, you will just search for your hash table here in your hash table.
You will search for an object that has a status positive, that has a status through.
So this object will be returned, otherwise no will be returned.
But this is just for simplicity.
You can have any any anything here, any type of object that you may be returning a basic T object if
you want to.
Also, you can see the synchronous keyword has been used for both methods because as I said, this object
pattern can be can cause some problems in terms of multi threading.
So if you're using if your program is running in a multi trading environment, if you're performing
several tasks at once, you may have some problems when checking in and out specific objects.
This is the robot's pool class that will extend the object pool.
So I'll be using the robot's class that I define in a previous Loreal.
And here we have to create.
As you can see, the great method will assign I will create a new robot, will assign a random ID here,
will create an empty array list and an empty set of components.
The array list was for the features of the robot.
We may not know at the creation time what will what the features for the robot will be.
So it's better to create some imperialist and empty components, whatever, whatever properties your
class have, because then at the wrong time you may need to populate those those properties.
But at the beginning you just created the object and then the program will handle the details for or
for this particular object.
I will recap a bit the robot class as well.
You can see there are only three properties here.
A constructor try to mimic more complex object by putting a more complex constructor with more than
two properties and also gethers in setters for each and every one, the colonial.
However, the implementation of the control interface is not needed anymore.
So this is the only difference in this code between this tutorial and the previous one.
And the components class hasn't been changed.
So basically we have two strings, two properties, name and functionality and get.
And there's for each of them.
And as you can see in the app class, we just create a new robot ball and we create our first robot
by calling the create method from inside the robot pool.
And the second robot will be created using the same method.
But however, we do some some tasks here between these lines and we decide that we need to decommission
our first robot.
So what we need to do is to check this out, to call the check out method.
And as a as an argument, we will supply the name of the object that we want to check out.
This is pretty straightforward and this is also available.
So we're checking in a new a new robot.
This will be the checking method will be called and a new robot will be returned as the third robot.
So this is kind of it.
It's pretty.
It's pretty complex.
This is an overly simplified example.
But things in real life tend to be very complex and use case for this might be when you will you need
to maybe to connect to a specific database and you might need an object for that.
You may need an object for creating a data connection to my school or a school or whatever your database
provider is.
And an object can be used for that.
But as I said in the previous video, it's better to have a single tone object for for the pool.
And also you may need to apply a design pattern to the create method as well for, you know, just making
things more intuitive when reading the code.
So you may apply a factory or a builder pattern for or for a discrete method.
But as I said, this is a very simplified example here.
So we won't use we won't make this more complicated than it is.
That's kind of it.
So join me in the next tutorial where we are going to discuss about the structural design patterns.
So see you in the next, Loreal.