title
State Design Pattern
description
Code is Here: http://goo.gl/OEWg4
Welcome to my State Design Pattern Tutorial! I explain how the state pattern is used by using it to simulate an ATM machine.
I explain how you come to decide on the different states. I then show you how to design the interface that each state will use. We think about the methods that are needed for every class that implements the interface then.
All the steps are looked at from many directions and the code above will fill in the gaps.
detail
{'title': 'State Design Pattern', 'heatmap': [{'end': 300.777, 'start': 261.38, 'weight': 0.817}, {'end': 493.946, 'start': 474.597, 'weight': 0.797}], 'summary': 'Covers state design pattern, including its function of altering object behavior when its internal state changes, and discusses its application in atm state design pattern, implementation, logic, transition, and pin verification, emphasizing the use of different states and methods to manage the atm machine.', 'chapters': [{'end': 60.339, 'segs': [{'end': 40.993, 'src': 'embed', 'start': 0.089, 'weight': 0, 'content': [{'end': 4.051, 'text': 'Hello Internet, and welcome to part 20 of my Design Patterns video tutorial.', 'start': 0.089, 'duration': 3.962}, {'end': 6.872, 'text': "Today we're going to talk about the State Design Pattern.", 'start': 4.07, 'duration': 2.802}, {'end': 13.355, 'text': 'So what is the State Design Pattern? It allows objects to alter its behavior when its internal state changes.', 'start': 6.972, 'duration': 6.383}, {'end': 17.096, 'text': 'And in doing so, the object will appear to change its class.', 'start': 13.755, 'duration': 3.341}, {'end': 21.938, 'text': "Just like in previous Design Pattern tutorials, this one's all about composition.", 'start': 17.376, 'duration': 4.562}, {'end': 28.401, 'text': "And you're going to have three main parts, and this is going to be probably the most confusing slide you see in this whole entire presentation.", 'start': 22.098, 'duration': 6.303}, {'end': 30.723, 'text': 'And of course tons of code is going to follow this.', 'start': 28.621, 'duration': 2.102}, {'end': 33.826, 'text': "First you're going to have what is called the context or the account.", 'start': 30.963, 'duration': 2.863}, {'end': 40.993, 'text': "What it's going to do is maintain an instance of a concrete state subclass that is going to define the current state.", 'start': 33.946, 'duration': 7.047}], 'summary': 'Part 20 covers the state design pattern, allowing objects to alter behavior based on internal state changes.', 'duration': 40.904, 'max_score': 0.089, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo89.jpg'}], 'start': 0.089, 'title': 'State design pattern', 'summary': 'Discusses the state design pattern, outlining its function of altering object behavior when its internal state changes, and presents three main parts: context, state, and concrete state.', 'chapters': [{'end': 60.339, 'start': 0.089, 'title': 'State design pattern tutorial', 'summary': 'Discusses the state design pattern, explaining its function of altering object behavior when its internal state changes, using composition, and presents three main parts: context, state, and concrete state.', 'duration': 60.25, 'highlights': ['The State Design Pattern allows objects to alter their behavior when their internal state changes, making the object appear to change its class.', 'The tutorial discusses three main parts: context (or account), which maintains an instance of a concrete state subclass defining the current state; state, defining an interface for encapsulating behavior associated with a particular state of the context; and concrete state, where each subclass implements behavior associated with a state of the context.']}], 'duration': 60.25, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo89.jpg', 'highlights': ['The tutorial discusses three main parts: context (or account), which maintains an instance of a concrete state subclass defining the current state; state, defining an interface for encapsulating behavior associated with a particular state of the context; and concrete state, where each subclass implements behavior associated with a state of the context.', 'The State Design Pattern allows objects to alter their behavior when their internal state changes, making the object appear to change its class.']}, {'end': 442.991, 'segs': [{'end': 139.914, 'src': 'embed', 'start': 101.558, 'weight': 0, 'content': [{'end': 103.379, 'text': 'otherwise things can get quite confusing.', 'start': 101.558, 'duration': 1.821}, {'end': 108.32, 'text': 'Then what you want to do is think about all the different ways the user can use the ATM.', 'start': 103.559, 'duration': 4.761}, {'end': 113.961, 'text': 'They can insert a card, they can eject a card, they can insert a pin, and they can request cache.', 'start': 108.44, 'duration': 5.521}, {'end': 118.523, 'text': "and that is going to be the basis of how we're going to implement this state design pattern.", 'start': 114.281, 'duration': 4.242}, {'end': 121.044, 'text': 'and here you see the actual implementation.', 'start': 118.523, 'duration': 2.521}, {'end': 123.565, 'text': 'here is going to be the interface.', 'start': 121.044, 'duration': 2.521}, {'end': 129.588, 'text': 'this over here, by the way, is the context which we talked about previously, if you want to rewind and look at that again,', 'start': 123.565, 'duration': 6.023}, {'end': 132.29, 'text': "but this is the interface that everything's going to be based off of.", 'start': 129.588, 'duration': 2.702}, {'end': 133.21, 'text': 'and what did i do here?', 'start': 132.29, 'duration': 0.92}, {'end': 139.914, 'text': 'i just listed all the methods that a user is going to be able to do in regards to using a ATM machine.', 'start': 133.21, 'duration': 6.704}], 'summary': 'Implementation of state design pattern for atm, listing user methods.', 'duration': 38.356, 'max_score': 101.558, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo101558.jpg'}, {'end': 261.04, 'src': 'embed', 'start': 237.15, 'weight': 2, 'content': [{'end': 244.772, 'text': "Well, we're going to define all of the ways that the user is going to be able to work with our ATM machine.", 'start': 237.15, 'duration': 7.622}, {'end': 247.533, 'text': "So they're going to be able to insert a card.", 'start': 244.972, 'duration': 2.561}, {'end': 249.634, 'text': "They're going to be able to eject a card.", 'start': 247.553, 'duration': 2.081}, {'end': 252.736, 'text': "They're also going to be able to insert a pin.", 'start': 249.774, 'duration': 2.962}, {'end': 256.858, 'text': "And then we're just going to go in here and go int pin entered.", 'start': 253.236, 'duration': 3.622}, {'end': 261.04, 'text': "And then they're also going to be able to request cash.", 'start': 257.158, 'duration': 3.882}], 'summary': 'Atm machine functions include card insertion, ejection, pin insertion, and cash withdrawal.', 'duration': 23.89, 'max_score': 237.15, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo237150.jpg'}, {'end': 307.963, 'src': 'heatmap', 'start': 261.38, 'weight': 3, 'content': [{'end': 268.683, 'text': "And this is also, just to be simple here, I'm just going to have this be an int because I've never seen an ATM shoot out pennies.", 'start': 261.38, 'duration': 7.303}, {'end': 269.543, 'text': 'And there you go.', 'start': 268.983, 'duration': 0.56}, {'end': 270.484, 'text': 'There is your interface.', 'start': 269.583, 'duration': 0.901}, {'end': 272.665, 'text': "That's all you're going to have to do with this guy.", 'start': 270.544, 'duration': 2.121}, {'end': 283.049, 'text': "Now what I'm going to do is go into atm-machine.java and start playing around with the context or the account that we refer to right here.", 'start': 272.845, 'duration': 10.204}, {'end': 284.43, 'text': 'See, context account.', 'start': 283.209, 'duration': 1.221}, {'end': 286.691, 'text': "That's going to be our actual ATM machine.", 'start': 284.59, 'duration': 2.101}, {'end': 287.651, 'text': 'So back to the code.', 'start': 286.791, 'duration': 0.86}, {'end': 292.35, 'text': "All right, now inside of ATM machine, we're going to define all our different states.", 'start': 287.967, 'duration': 4.383}, {'end': 296.294, 'text': "And I haven't defined these yet, so error message is going to pop up all over the place.", 'start': 292.531, 'duration': 3.763}, {'end': 298.415, 'text': "So we're just going to go copy that.", 'start': 296.554, 'duration': 1.861}, {'end': 300.777, 'text': "And there's basically going to be four states.", 'start': 298.675, 'duration': 2.102}, {'end': 302.578, 'text': "So it's going to have has card.", 'start': 300.837, 'duration': 1.741}, {'end': 304.72, 'text': "And then there's going to be no card.", 'start': 302.739, 'duration': 1.981}, {'end': 307.963, 'text': "And then we're going to have has correct in.", 'start': 304.82, 'duration': 3.143}], 'summary': 'The transcript discusses defining states in an atm machine with four states: has card, no card, has correct in.', 'duration': 46.583, 'max_score': 261.38, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo261380.jpg'}], 'start': 60.419, 'title': 'Atm state design pattern', 'summary': 'Covers the atm state design pattern, detailing the four states an atm can have, the user actions, and the implementation emphasizing the use of different states and methods to manage the atm machine, with a focus on defining states, monitoring cash availability, and allowing state transitions.', 'chapters': [{'end': 139.914, 'start': 60.419, 'title': 'Atm state design pattern', 'summary': 'Explains the atm state design pattern, illustrating the four states an atm can have and the user actions, emphasizing the importance of minimizing states to avoid confusion and providing insight into the interface implementation.', 'duration': 79.495, 'highlights': ['The chapter emphasizes the importance of minimizing states to avoid confusion and provides insight into the interface implementation, which lists all the methods a user can perform with an ATM machine.', 'It explains the four states an ATM can have: card inserted or not, correct pin entered or not, and having cash or not.', 'The chapter discusses the different ways a user can interact with the ATM, including inserting/ejecting a card, entering a pin, and requesting cash.']}, {'end': 442.991, 'start': 140.074, 'title': 'Atm state design pattern', 'summary': 'Discusses the implementation of the atm state design pattern, emphasizing the use of different states and methods to manage the atm machine, with a focus on defining states, monitoring cash availability, and allowing state transitions.', 'duration': 302.917, 'highlights': ['The chapter discusses the implementation of the ATM state design pattern, emphasizing the use of different states and methods to manage the ATM machine.', 'The ATM machine is defined with four different states: has card, no card, has correct pin, and ATM out of money, with the initial state set as no card.', 'The ATM machine also monitors the availability of cash inside the machine and tracks whether the correct pin number was entered using Boolean values.', 'State transitions are facilitated based on certain actions, such as changing the state to no cash when the machine runs out of money.']}], 'duration': 382.572, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo60419.jpg', 'highlights': ['The chapter emphasizes the importance of minimizing states to avoid confusion and provides insight into the interface implementation, which lists all the methods a user can perform with an ATM machine.', 'The chapter discusses the implementation of the ATM state design pattern, emphasizing the use of different states and methods to manage the ATM machine.', 'It explains the four states an ATM can have: card inserted or not, correct pin entered or not, and having cash or not.', 'The ATM machine is defined with four different states: has card, no card, has correct pin, and ATM out of money, with the initial state set as no card.']}, {'end': 614.767, 'segs': [{'end': 503.571, 'src': 'heatmap', 'start': 474.597, 'weight': 0, 'content': [{'end': 478.039, 'text': "And then what we're going to do is we're just going to pass it to the right state.", 'start': 474.597, 'duration': 3.442}, {'end': 480.7, 'text': 'See, ATM state is going to be changing.', 'start': 478.259, 'duration': 2.441}, {'end': 484.942, 'text': 'And the way that ATM state is going to be changing is with this guy right here.', 'start': 480.86, 'duration': 4.082}, {'end': 493.946, 'text': 'So all this guy is going to do is take whatever you send to it and pass it along to the new state that is being defined by the ATM.', 'start': 485.062, 'duration': 8.884}, {'end': 499.408, 'text': "And that's either I have card, I don't have a card, I have a pin, or I have no cash.", 'start': 493.986, 'duration': 5.422}, {'end': 501.629, 'text': "So don't let that confuse you.", 'start': 499.968, 'duration': 1.661}, {'end': 503.571, 'text': "And then we're going to go eject card.", 'start': 501.969, 'duration': 1.602}], 'summary': 'Atm state will change to defined states: have card, no card, have pin, no cash.', 'duration': 45.075, 'max_score': 474.597, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo474597.jpg'}], 'start': 443.319, 'title': 'Atm state design pattern', 'summary': 'Discusses the atm state design pattern implementation, highlighting benefits of multiple classes and transitioning between states to enhance code understandability and efficiency.', 'chapters': [{'end': 614.767, 'start': 443.319, 'title': 'Atm state design pattern', 'summary': 'Discusses the implementation of the atm state design pattern, emphasizing the benefits of using multiple classes and the process of transitioning between different states, aiming to make the code more understandable and efficient.', 'duration': 171.448, 'highlights': ['The benefits of using multiple classes and the process of transitioning between different states in the ATM state design pattern are emphasized, aiming to make the code more understandable and efficient.', 'The implementation of the ATM state design pattern is described, showcasing the use of various classes for defining different states and methods for transitioning between states.', 'The need to define multiple classes for different states and methods for transitioning between states in the ATM state design pattern is highlighted, emphasizing the improvement in code organization and understandability.', 'The process of transitioning between different states in the ATM state design pattern is explained, highlighting the use of specific methods for actions like ejecting a card, requesting cash, and inserting a pin, all aimed at improving code efficiency and user interaction.']}], 'duration': 171.448, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo443319.jpg', 'highlights': ['The implementation of the ATM state design pattern is described, showcasing the use of various classes for defining different states and methods for transitioning between states.', 'The process of transitioning between different states in the ATM state design pattern is explained, highlighting the use of specific methods for actions like ejecting a card, requesting cash, and inserting a pin, all aimed at improving code efficiency and user interaction.', 'The benefits of using multiple classes and the process of transitioning between different states in the ATM state design pattern are emphasized, aiming to make the code more understandable and efficient.', 'The need to define multiple classes for different states and methods for transitioning between states in the ATM state design pattern is highlighted, emphasizing the improvement in code organization and understandability.']}, {'end': 831.559, 'segs': [{'end': 656.478, 'src': 'embed', 'start': 614.827, 'weight': 0, 'content': [{'end': 617.109, 'text': 'HasCard, NoCard, HasPin, and NoCache.', 'start': 614.827, 'duration': 2.282}, {'end': 620.812, 'text': "So let's go into HasCard.java.", 'start': 617.409, 'duration': 3.403}, {'end': 621.452, 'text': 'And there we are.', 'start': 620.832, 'duration': 0.62}, {'end': 623.714, 'text': 'And you can see here, implements ATM state.', 'start': 621.652, 'duration': 2.062}, {'end': 628.378, 'text': "And if we'll put the mouse over this, it's going to say add unimplemented methods.", 'start': 624.014, 'duration': 4.364}, {'end': 634.124, 'text': 'And then I just need to come in here and think about logically what I need to do in all these different situations.', 'start': 628.719, 'duration': 5.405}, {'end': 641.811, 'text': "Now one thing I'm going to have to do is I'm going to need to store the context, which is the actual object that I'm going to be working with here.", 'start': 634.304, 'duration': 7.507}, {'end': 652.336, 'text': "And also I'm going to have to come in here and go public as card, which is going to be when they pass over the ATM object that we are required to use,", 'start': 642.091, 'duration': 10.245}, {'end': 656.478, 'text': "so that we're using the same ATM object and not, you know, messing that up.", 'start': 652.336, 'duration': 4.142}], 'summary': 'Implementing atm state in hascard.java, requires storing context and using the same atm object.', 'duration': 41.651, 'max_score': 614.827, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo614827.jpg'}, {'end': 817.989, 'src': 'embed', 'start': 674.67, 'weight': 2, 'content': [{'end': 679.014, 'text': 'From now on, this is piece of cake, no problem, totally understandable.', 'start': 674.67, 'duration': 4.344}, {'end': 685.378, 'text': "You're going to have to say, you can't enter more than one card.", 'start': 679.194, 'duration': 6.184}, {'end': 686.339, 'text': "See? That's all.", 'start': 685.638, 'duration': 0.701}, {'end': 686.839, 'text': "You're done.", 'start': 686.519, 'duration': 0.32}, {'end': 687.58, 'text': "And that's it.", 'start': 686.859, 'duration': 0.721}, {'end': 688.541, 'text': "That's all you need to do.", 'start': 687.7, 'duration': 0.841}, {'end': 692.065, 'text': "Now, we don't need to change the state because, well, it has a card.", 'start': 688.821, 'duration': 3.244}, {'end': 693.326, 'text': 'They tried to enter a new card.', 'start': 692.105, 'duration': 1.221}, {'end': 694.687, 'text': "The state didn't change.", 'start': 693.346, 'duration': 1.341}, {'end': 695.969, 'text': 'You just gave them a warning sign.', 'start': 694.707, 'duration': 1.262}, {'end': 702.235, 'text': "Okay, so what are we going to do if they try to eject the card? In that situation, we're going to print out a different message.", 'start': 695.989, 'duration': 6.246}, {'end': 704.236, 'text': "Let's just say card ejected.", 'start': 702.435, 'duration': 1.801}, {'end': 704.936, 'text': 'There we are.', 'start': 704.416, 'duration': 0.52}, {'end': 710.918, 'text': "And then what are we going to do? Well, now we don't have a card, so we're going to need to change the state for our ATM machine.", 'start': 705.136, 'duration': 5.782}, {'end': 713.979, 'text': "So we're going to go ATM machine, which comes from this guy right here.", 'start': 710.958, 'duration': 3.021}, {'end': 717.58, 'text': "And then we're going to have to go set ATM state.", 'start': 714.139, 'duration': 3.441}, {'end': 721.302, 'text': 'We need to change the state for our ATM machine because it just changed.', 'start': 717.78, 'duration': 3.522}, {'end': 723.843, 'text': "And to set it, we're going to go ATM machine.", 'start': 721.682, 'duration': 2.161}, {'end': 727.084, 'text': "We're going to say get no card state.", 'start': 723.863, 'duration': 3.221}, {'end': 728.184, 'text': 'Pass that back.', 'start': 727.344, 'duration': 0.84}, {'end': 728.904, 'text': 'Boom, boom, boom.', 'start': 728.244, 'duration': 0.66}, {'end': 730.785, 'text': 'And now the state has changed.', 'start': 729.184, 'duration': 1.601}, {'end': 737.089, 'text': 'And set ATM state is found where? In ATM machine dot Java.', 'start': 731.085, 'duration': 6.004}, {'end': 740.311, 'text': 'And if you scroll down, see? Set ATM state.', 'start': 737.289, 'duration': 3.022}, {'end': 743.273, 'text': 'And how is the state being passed? Right down here.', 'start': 740.631, 'duration': 2.642}, {'end': 744.094, 'text': 'With these guys.', 'start': 743.453, 'duration': 0.641}, {'end': 744.954, 'text': 'See? These.', 'start': 744.334, 'duration': 0.62}, {'end': 746.415, 'text': 'Git da da da da da.', 'start': 745.214, 'duration': 1.201}, {'end': 747.936, 'text': "Alright, so let's get back in here.", 'start': 746.595, 'duration': 1.341}, {'end': 749.317, 'text': 'Continue fixing this up.', 'start': 748.176, 'duration': 1.141}, {'end': 755.301, 'text': "So that's all we're doing is dynamically changing the class based off of different actions that are being performed.", 'start': 749.337, 'duration': 5.964}, {'end': 758.902, 'text': 'so then they come in and they say okay, well, i want to insert a pin.', 'start': 755.541, 'duration': 3.361}, {'end': 761.863, 'text': 'well, they inserted cards, so that sort of makes sense.', 'start': 758.902, 'duration': 2.961}, {'end': 767.205, 'text': "so now we're going to go pin entered and we're going to check is it equal to one, two, three, four?", 'start': 761.863, 'duration': 5.342}, {'end': 771.786, 'text': "now i really again we're not checking anything here, real sophisticated, okay.", 'start': 767.205, 'duration': 4.581}, {'end': 776.267, 'text': "so let's just say yeah, they entered one, two, three, four, and that is the correct one.", 'start': 771.786, 'duration': 4.481}, {'end': 779.459, 'text': 'now you could say something like correct Pin.', 'start': 776.267, 'duration': 3.192}, {'end': 784.325, 'text': "And then what are you going to need to do? Well, you're going to have to change ATM machine.", 'start': 779.86, 'duration': 4.465}, {'end': 787.949, 'text': "You're going to have to say, hey, the ATM machine, correct pin entered.", 'start': 784.345, 'duration': 3.604}, {'end': 789.731, 'text': "This guy right here, well, it's false.", 'start': 788.049, 'duration': 1.682}, {'end': 791.272, 'text': 'So they entered the correct pin.', 'start': 789.991, 'duration': 1.281}, {'end': 795.277, 'text': "So now what are we going to have to do? Well, we're going to have to come in and change that value.", 'start': 791.292, 'duration': 3.985}, {'end': 799.621, 'text': 'So ATM machine, correct pin entered.', 'start': 795.497, 'duration': 4.124}, {'end': 801.163, 'text': "And we're going to set it to true.", 'start': 799.902, 'duration': 1.261}, {'end': 801.68, 'text': 'There we are.', 'start': 801.34, 'duration': 0.34}, {'end': 802.18, 'text': 'All done.', 'start': 801.84, 'duration': 0.34}, {'end': 803.561, 'text': 'And then, of course, die.', 'start': 802.401, 'duration': 1.16}, {'end': 804.021, 'text': 'All right.', 'start': 803.721, 'duration': 0.3}, {'end': 804.982, 'text': 'So we got that set.', 'start': 804.061, 'duration': 0.921}, {'end': 808.624, 'text': 'And then what do we need to do? Well, we need to change the state for this.', 'start': 805.102, 'duration': 3.522}, {'end': 812.005, 'text': 'And that state is going to be a git has pin.', 'start': 808.984, 'duration': 3.021}, {'end': 814.107, 'text': 'Done We just did all that the right way.', 'start': 812.206, 'duration': 1.901}, {'end': 816.268, 'text': "And then we're going to come in and go else.", 'start': 814.407, 'duration': 1.861}, {'end': 817.989, 'text': 'They entered the wrong pin.', 'start': 816.608, 'duration': 1.381}], 'summary': 'Dynamically changing the atm state based on card and pin inputs.', 'duration': 143.319, 'max_score': 674.67, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo674670.jpg'}], 'start': 614.827, 'title': 'Atm state logic, change, and pin verification', 'summary': 'Delves into the implementation of atm state logic, emphasizing hascard.java file, state change, and message printing, and pin verification process, ensuring secure and efficient atm operations.', 'chapters': [{'end': 695.969, 'start': 614.827, 'title': 'Atm state logic implementation', 'summary': 'Discusses the implementation of atm state logic, focusing on the hascard.java file, where the atm object is passed as a reference and logic for managing card insertion is detailed, ensuring that only one card can be used at a time.', 'duration': 81.142, 'highlights': ['The HasCard.java file implements ATM state and includes logic for managing card insertion, ensuring only one card can be used at a time.', 'The necessity to store and utilize the ATM object is emphasized to avoid discrepancies and ensure consistent usage.', 'The logic for handling situations where a user attempts to insert another card when one is already present is outlined, preventing multiple card entries and maintaining the current state.']}, {'end': 758.902, 'start': 695.989, 'title': 'Atm state change and message printing', 'summary': 'Discusses the process of dynamically changing the state of an atm machine and printing out different messages based on user actions, with a specific focus on handling card ejection and pin insertion.', 'duration': 62.913, 'highlights': ['The process involves dynamically changing the state of the ATM machine and printing out different messages based on user actions, such as card ejection and pin insertion.', "When the card is ejected, a 'card ejected' message is printed, and the state for the ATM machine is changed, utilizing the set ATM state function in ATM machine dot Java.", 'The state of the ATM machine is changed by calling the set ATM state function, specifically invoking the get no card state to reflect the absence of a card.', 'The process of dynamically changing the class based on different actions being performed is described, showcasing the flexibility in handling user interactions.']}, {'end': 831.559, 'start': 758.902, 'title': 'Atm pin verification', 'summary': 'Discusses the process of verifying a pin entered in an atm machine, including setting the correct pin, updating the machine state, and handling incorrect pin entries.', 'duration': 72.657, 'highlights': ["The ATM machine verifies the entered PIN by checking if it is equal to '1234'.", "If the correct PIN is entered, the ATM machine updates the 'correct pin entered' status to true and changes the state to 'git has pin'.", "If an incorrect PIN is entered, the ATM machine handles it by setting the 'correct pin entered' status to false and taking appropriate action."]}], 'duration': 216.732, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo614827.jpg', 'highlights': ['The HasCard.java file manages card insertion, allowing only one card at a time.', 'Utilize the ATM object to ensure consistent usage and avoid discrepancies.', 'Prevent multiple card entries and maintain the current state.', 'Dynamically change the ATM machine state and print messages based on user actions.', "Print a 'card ejected' message and change the ATM machine state upon card ejection.", 'Change the ATM machine state by invoking the set ATM state function.', 'Describe the flexibility in handling user interactions by dynamically changing the class based on actions.', "Verify the entered PIN by checking if it is equal to '1234'.", "Update the 'correct pin entered' status to true and change the state to 'git has pin' upon correct PIN entry.", "Handle incorrect PIN entry by setting the 'correct pin entered' status to false and taking appropriate action."]}, {'end': 1250.229, 'segs': [{'end': 937.562, 'src': 'embed', 'start': 915.164, 'weight': 0, 'content': [{'end': 923.173, 'text': "we're going to change our card state to yes card state because we got a card, because they just inserted a card,", 'start': 915.164, 'duration': 8.009}, {'end': 925.736, 'text': "so you know that's great and then eject card.", 'start': 923.173, 'duration': 2.563}, {'end': 926.837, 'text': 'well, what are we going to do here?', 'start': 925.736, 'duration': 1.101}, {'end': 930.341, 'text': "well, we're in no card, so that doesn't work.", 'start': 926.837, 'duration': 3.504}, {'end': 937.562, 'text': "so we're going to print out a message enter a card first, can't eject a card if they don't give us one.", 'start': 930.341, 'duration': 7.221}], 'summary': "The system changes card state to 'yes' when a card is inserted and prompts to eject it if no card is present.", 'duration': 22.398, 'max_score': 915.164, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo915164.jpg'}, {'end': 1131.58, 'src': 'embed', 'start': 1104.838, 'weight': 1, 'content': [{'end': 1116.768, 'text': 'And then maybe as one additional little change, we could throw something in here, like if ATM machine cash in machine is less than or equal to zero,', 'start': 1104.838, 'duration': 11.93}, {'end': 1119.871, 'text': "then we're going to also come in here and change the state.", 'start': 1116.768, 'duration': 3.103}, {'end': 1121.472, 'text': 'for our ATM machine.', 'start': 1120.151, 'duration': 1.321}, {'end': 1126.416, 'text': 'And that state is going to be set to get no cash state.', 'start': 1121.792, 'duration': 4.624}, {'end': 1129.799, 'text': 'See, the ATM machine is officially out of cash.', 'start': 1126.576, 'duration': 3.223}, {'end': 1130.76, 'text': "And I think that's it.", 'start': 1129.979, 'duration': 0.781}, {'end': 1131.58, 'text': 'Yes, it is.', 'start': 1130.96, 'duration': 0.62}], 'summary': 'If atm machine cash is less than or equal to zero, change state to get no cash state.', 'duration': 26.742, 'max_score': 1104.838, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo1104838.jpg'}], 'start': 831.559, 'title': 'Atm state transition and design pattern', 'summary': 'Discusses the transition of the atm state involving changing states upon card insertion and ejection, and prompts the user for actions, as well as explains the implementation of the state design pattern for an atm machine, demonstrating its functionality with examples.', 'chapters': [{'end': 937.562, 'start': 831.559, 'title': 'Atm state transition', 'summary': 'Discusses the transition of the atm state from hascard to nocard, involving changing states upon card insertion and ejection, and prompting the user for actions such as entering a pin and displaying error messages.', 'duration': 106.003, 'highlights': ['The transition of the ATM state from hasCard to NoCard involves changing the state upon card insertion and ejection, prompting the user for actions such as entering a pin and displaying error messages.', 'Upon card ejection, the state changes from hasCard to no card state, while upon card insertion, the state changes to yes card state, prompting the user to enter a pin.', 'When in the NoCard state, the ATM prompts the user to enter a pin upon card insertion and displays a message to enter a card first upon attempting to eject a non-existent card.']}, {'end': 1250.229, 'start': 937.562, 'title': 'Atm state design pattern', 'summary': "Explains the implementation of the state design pattern for an atm machine, including the logic for handling card insertion, pin entry, cash request, and managing the machine's cash availability, with an example demonstrating the functionality of the implemented pattern.", 'duration': 312.667, 'highlights': ["The chapter explains the implementation of the state design pattern for an ATM machine It details the application of the state design pattern to manage the various states of an ATM machine, such as 'no card', 'has card', 'has pin', and 'no cash' for handling different user actions.", 'Example demonstrating the functionality of the implemented pattern A demonstration showcases the behavior of the implemented state design pattern, including scenarios such as card insertion, pin entry, cash request, and handling situations when the ATM machine has insufficient funds.', 'Logic for handling card insertion, pin entry, and cash request The transcript provides detailed logic for managing the process of card insertion, pin entry, and cash request, including scenarios for valid and invalid user actions.', "Management of the machine's cash availability The transcript outlines the logic for managing the cash availability within the ATM machine, including checks for sufficient funds before processing cash withdrawal requests and updating the machine's cash reserves after successful transactions."]}], 'duration': 418.67, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/MGEx35FjBuo/pics/MGEx35FjBuo831559.jpg', 'highlights': ['The transition of the ATM state from hasCard to NoCard involves changing the state upon card insertion and ejection, prompting the user for actions such as entering a pin and displaying error messages.', "The chapter explains the implementation of the state design pattern for an ATM machine It details the application of the state design pattern to manage the various states of an ATM machine, such as 'no card', 'has card', 'has pin', and 'no cash' for handling different user actions.", 'Example demonstrating the functionality of the implemented pattern A demonstration showcases the behavior of the implemented state design pattern, including scenarios such as card insertion, pin entry, cash request, and handling situations when the ATM machine has insufficient funds.']}], 'highlights': ['The State Design Pattern allows objects to alter their behavior when their internal state changes, making the object appear to change its class.', 'The tutorial discusses three main parts: context (or account), which maintains an instance of a concrete state subclass defining the current state; state, defining an interface for encapsulating behavior associated with a particular state of the context; and concrete state, where each subclass implements behavior associated with a state of the context.', 'The chapter discusses the implementation of the ATM state design pattern, emphasizing the use of different states and methods to manage the ATM machine.', 'The chapter emphasizes the importance of minimizing states to avoid confusion and provides insight into the interface implementation, which lists all the methods a user can perform with an ATM machine.', 'The ATM machine is defined with four different states: has card, no card, has correct pin, and ATM out of money, with the initial state set as no card.', 'The process of transitioning between different states in the ATM state design pattern is explained, highlighting the use of specific methods for actions like ejecting a card, requesting cash, and inserting a pin, all aimed at improving code efficiency and user interaction.', 'The benefits of using multiple classes and the process of transitioning between different states in the ATM state design pattern are emphasized, aiming to make the code more understandable and efficient.', 'The need to define multiple classes for different states and methods for transitioning between states in the ATM state design pattern is highlighted, emphasizing the improvement in code organization and understandability.', 'The transition of the ATM state from hasCard to NoCard involves changing the state upon card insertion and ejection, prompting the user for actions such as entering a pin and displaying error messages.', "The chapter explains the implementation of the state design pattern for an ATM machine It details the application of the state design pattern to manage the various states of an ATM machine, such as 'no card', 'has card', 'has pin', and 'no cash' for handling different user actions.", 'Example demonstrating the functionality of the implemented pattern A demonstration showcases the behavior of the implemented state design pattern, including scenarios such as card insertion, pin entry, cash request, and handling situations when the ATM machine has insufficient funds.']}