er what that does is that our bin will inherit 1:29 all of the methods from ArrayBlockingQueue. 1:33 That means methods like add and add all will show up in its API and that's great. 1:35 But all the methods are here. 1:40 Poll. 1:43 That's a little strange for use of our API, right? 1:44 We would want them to know how to release the item from the bin so 1:47 we could do something like this, we could just create a synonym. 1:49 But see how polluted our API is? 1:53 It has a contains method, but that's not really important. 1:55 Is it? 1:59 You know that all the items in here are basically the same. 1:59 We probably never want to call this. 2:02 Oh man, that reminds me, too. 2:05 We would need to make sure that the add method doesn't allow you to add any item. 2:06 We need to fix that by overriding add and adding proper blocking. 2:11 Something like this [SOUND]. 2:15 See how we're able to block if there's already something in the bin, 2:19 just like Tex wants. 2:23 And if there is, we throw an exception if there are any different types of items. 2:24 Otherwise, we call the parent add method defined in the superclass 2:29 ArrayBlockingQueue. 2:32 This is how you modify how inherited methods work. 2:34 It's called polymorphism, and it's pretty powerful. 2:36 Now we've talked about this before. 2:40 And remember it roughly translates to, to "many forms". 2:41 But the different forms here being the classes that extend the parent. 2:45 Each child class can use inherited methods and or 2:49 change them as needed by their modified class or form. 2:52 But if we think about this, we are going to have to do this overwriting for 2:56 every exposed public method that adds or changes items in the queue. 3:00 So we covered add, but we need to do addAll and put as well. 3:05 This is gonna get time consuming, right? 3:09 It feels like inheriting all those methods means that I'm responsible to make sure 3:11 that code I didn't write works the way that I want it to. 3:15 Now because it's exposed publicly anyone could use any of these methods, right? 3:19 And because we explicitly said that we want all the methods exposed through 3:24 inheritance, we have to make sure that they work the way that we want them to. 3:29 After looking at this in more detail, I'm not sure we want all this stuff exposed. 3:34 So let's take a look at the composition approach. 3:38 The basic concept is just to re-use code that you need and 3:41 encapsulate the fact that you're using it at all. 3:44 Here, let's take a look. 3:46 So first we create our class. 3:48 It doesn't extend anything, it's just a normal class. 3:49 it's going to have a private field that must implement the blocking 3:52 queue interface of items, we'll call it items. 3:55 Blocking queue is the interface that helps us keep track of the max number of items. 3:59 Now, remember we want to declare with the interface so 4:04 that we can choose whatever specific implementation we want later. 4:07 So now we'll add our constructor. 4:11 And here, 4:14 we want to choose the implementation for the [SOUND] blocking queue. 4:14 Array blocking queue. 4:18 In the constructor, 4:20 we'll require the creator to specify the maximum number of items. 4:21 Then we'll use that to instantiate the instance and 4:26 choose the implementation array blocking queue. 4:29 And pass in the max items allowed. 4:32 Note that I used the diamond operator, 4:35 no need to redefine that it's a blocking queue of items. 4:37 So, we know that we want to be able to check the bin as empty. 4:41 So let's do it. 4:45 See how we're only exposing the methods that we want, and 4:46 we can also name them any way we want. 4:49 So we can add specific terms too, right? 4:52 Like so each of these spaces in the bins are called slots. 4:54 [SOUND] So, why not get available slots? 4:57 But check out this restock method. 5:01 [SOUND] This replaces the add method that we had from the inherited stock. 5:03 See how that bins API is pretty much exactly what we mean, 5:07 while using basically the same tricks. 5:10 And remember, because we've encapsulat