in this video i'm going to talk about the command design pattern you can use this pattern to represent commands and have control over when they're executed i'll show you an example of how this works and then also build on top of this example and do something that a lot of non-destructive editors also have which is nice undo and redo behavior but first let's talk about the sponsor of this video skillshare skillshare is an online learning community with thousands of inspiring classes for creators explore new skills deepen existing passions and get lost in creativity skillshare has many classes on web development programming in python software engineering and software design at the moment i'm following frank kane's course on data science and machine learning with python it's really comprehensive it contains lessons about statistics data types clustering algorithms decision trees governs libraries such as pandas basically everything you need to know in order to get started skillshare is curated for learning there are no ads and they're always launching new premium classes so you can stay focused and follow wherever your creativity takes you the first NUMBER_TOKEN of my subscribers to click the link in the description we'll get a one month free trial of skillshare so you can start exploring your creativity today the command design pattern is a behavioral pattern that provides a way to encapsulate all knowledge about performing a certain operation into a single object here's a class diagram i'll show you how to use it to make transactions in the banking system more flexible and add undo and redo behavior to it banks are actually a great example of where you can apply the command pattern since in banks lots of the interactions are based around transactions or commands after i've implemented the command pattern and added undo and redo i'll show you one more thing that really takes the flexibility of this pattern to the next level let's dive in so we have two files here in a banking package there is an account file and a bank file it's pretty simple at the moment an account is basically your data class that contains a name a number and a balance we have a deposit and a withdraw method that basically adds and subtract something from the balance withdraw if the amount you try to withdraw more than there is in the account then you're going to get a value error and it simply adds subtracts it to the balance then a bank is basically a class that manages these accounts so there's a dictionary that contains mappings from accounts strings account names to accounts there's a create account method that gets a name and then creates an account with a random number there's a getaccount method that returns an account given the number and then there's a main file that then uses these two classes to play around with it a little bit so there's a bank we created we create a couple of accounts then account one deposits a hundred thousand cents so thousand euros and two and three as well so we all start with thousand euros then google pays our encodes NUMBER_TOKEN euros and i do that by calling both withdraw and deposit and that then becomes a transfer and then of course i run away immediately with the money so i withdraw all the money that i have and then i leave and go to a nice place in the bahamas or something and at the end i'm going to print the bank now normally of course you can't really print a bank
START_SPONSOR_TOKEN skillshare is an online learning community with thousands of inspiring classes for creators explore new skills deepen existing passions and get lost in creativity skillshare has many classes on web development programming in python software engineering and software design at the moment i'm following frank kane's course on data science and machine learning with python it's really comprehensive it contains lessons about statistics data types clustering algorithms decision trees governs libraries such as pandas basically everything you need to know in order to get started skillshare is curated for learning there are no ads and they're always launching new premium classes so you can stay focused and follow wherever your creativity takes you the first NUMBER_TOKEN of my subscribers to click the link in the description we'll get a one month free trial of skillshare so you can start exploring your creativity today the END_SPONSOR_TOKEN