State Pattern - Design Patterns (ep 17)

  Рет қаралды 147,594

Christopher Okhravi

Christopher Okhravi

Күн бұрын

Video series on Design Patterns for Object Oriented Languages. This time we look at the State Pattern.
00:00:00 Intro
00:01:50 Example
00:37:50 Definition
00:38:50 Definition in UML
00:43:37 Example in UML
00:51:20 Example in Code
01:10:41 Recap of code example
► The playlist
• Design Patterns in Obj...
► Head First: Design Patterns
geni.us/nlbA6
► Design Patterns: Elements of Reusable Object-Oriented Software
geni.us/PsXmo
► Great playlist on State Machines (amongst other things)
• Introduction to the Th...
💪 Patreon Community
/ christopherokhravi
📚 Products I Recommend
geni.us/71ZXF

Пікірлер: 262
@claudios
@claudios 6 жыл бұрын
An 80 minute video on a design pattern?! It really is Christmas, thanks Chris
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Thank you and Thank you for watching 🙂🙂
@MahmoudHbobati
@MahmoudHbobati 3 жыл бұрын
singleton pattern is 20 minutes!!! :)
@TheGGbond
@TheGGbond 3 жыл бұрын
wtf is wrong with u
@calexito9448
@calexito9448 2 жыл бұрын
@@TheGGbond reversed card actually
@openyourmind1694
@openyourmind1694 8 ай бұрын
I usually watch various tutorials, so I feel capable of giving a "competent" judgment: you have excellent presentation, comprehensive, organized, straight to the point, more than valid expertise, but what struck me is your enthusiasm and eagerness to convey competence. You deserve a like and a subscription. Thank you for your effort.
@iliassaek4609
@iliassaek4609 5 жыл бұрын
only with these videos I've aced the design patterns exam . Thank you .
@madhurajanaradhanan3368
@madhurajanaradhanan3368 2 жыл бұрын
What exam?
@zizimouad8291
@zizimouad8291 2 жыл бұрын
People don't understand the hard work puts for +1h explaining design pattern + editing, thank you 👌
@mayurdugar03
@mayurdugar03 2 жыл бұрын
Can I just take a moment and appreciate your efforts here! You made design pattern really understandable for me! Hats off to your efforts 🙏🤗 Wish you get everything required to be able to continue this series as well. Take care Christopher :)
@dscheme4427
@dscheme4427 4 жыл бұрын
36:00 definitions 51:23 code
@omarabdo6403
@omarabdo6403 4 жыл бұрын
that was a GREAT video! Chris, we're missing your videos on design patterns and different topics really bad! I hope you can find more time in the near future to help us learn more and become better software developers. Much love!
@MrMikomi
@MrMikomi 4 жыл бұрын
Watched at 2x speed; it's doable as I've some pre-existing knowledge of this pattern and this video makes a great refresher. Thank you very much.
@zieldistante
@zieldistante 4 жыл бұрын
I really like how you explain things (and sometimes go to other related things and go back). I thought I was the only one who explained things in this way! Thanks a lot for your videos.
@professorfontanez
@professorfontanez 5 жыл бұрын
There was a similar example in a textbook I used to teach Java which used three states LOCKED, UNLOCKED, and ROTATING. The transitions were "payment" for LOCKED --> UNLOCKED, "push" for UNLOCKED --> ROTATING, and "one revolution" for ROTATING --> LOCKED.
@parvez04
@parvez04 6 жыл бұрын
This is a really nice tutorial. Please keep it going. I am kind of addicted to your videos now.
@FunkyHotDog
@FunkyHotDog 6 жыл бұрын
You do a very good job in visualising these problems. Thank you, I'd be in trouble with my design pattern course without you.
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
I’m super glad to hear you feel that you’re learning faster :) I like to think that the quicker we can get the “known things” out of the way, then we can start to think about the “unknown things”. Which imho is where the really interesting issues lie :)
@JayJay-ki4mi
@JayJay-ki4mi Жыл бұрын
I've studied your videos for a while, and come back to them. But, I find it's only when I actually need to use a certain pattern that your videos make sense to me. I need to use the state pattern for game development and this video has been a God send. Thank you so much.
@nicolafontana2738
@nicolafontana2738 4 жыл бұрын
This has been very enlightning! Very well explained with the exact amount of detail, thanks a lot!
@pra86sat
@pra86sat 6 ай бұрын
I have been searching for Design pattern tutorials online like forever, to find something that can be more relatable to the software systems. But all I ever find are Ice cream, Pizza, Burger examples, which makes no sense what so ever. Thank you so much for all your efforts and making sense. I feel I am a better Software Engineer than I was 1:20 Hrs ago.
@monikaraut5266
@monikaraut5266 Жыл бұрын
What a explanation 🙌🙌 guys if you are confused whether to watch or not seeing the video duration, just give it a try. As otherwise you will have to waste double the time while reading articles
@olenaqwerty7895
@olenaqwerty7895 2 жыл бұрын
the best patterns explanation I've come across so far
@oztv_
@oztv_ 4 ай бұрын
you are perfect, i have only a few hours before exam i tried to watch 2x speed but it is still perfect because of body language, fluently speaking, diving into everything with clear explanation. need to say that i am still trying to learn english but i understand whole video. THANK YOU A LOT FOR YOUR EFFORT AND AMAZING JUMP CUTS.
@johnnguyen1655
@johnnguyen1655 Жыл бұрын
I watched tons of video about DP, your DP playlist make you special among the bests Chris!
@mdkhxyz
@mdkhxyz 3 жыл бұрын
The way of your teaching is very interesting and helpful. Thanks for your effort.
@ilnurgazizov2959
@ilnurgazizov2959 5 жыл бұрын
One of the best explanation! Thank you very much!
@RichardGomezMx
@RichardGomezMx 4 жыл бұрын
Amazing explication. I loved it. Congrats Chris. Great video. Thank you very much.
@BM-jy6cb
@BM-jy6cb 2 жыл бұрын
I love this entire series. Fantastic!
@finyog
@finyog 5 жыл бұрын
It is a very informative content, presented nicely. I like your videos and the way you explain things. Keep up the good work Chris 👍😊
@NoOne-pi8cj
@NoOne-pi8cj 6 жыл бұрын
Thank you so much for providing so many awesome videos. Even though I am unable to fully understand or master each every pattern, but you gave me the courage to dive deep into OOD. I will definitely read these two books again. Thank you !!!!
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
I’m glad to hear :) Thanks for commenting!
@ismailktami2727
@ismailktami2727 4 жыл бұрын
Thank youuuu sooo muchhhhhhh ! your the best way to understand the concrets concepts of DP
@hdanijel
@hdanijel 5 жыл бұрын
Hey man, I just found your channel. Immediately I knew I liked you, and it took me a while to figure it. It's cuz you look like Antonio Banderas! Your energy also is amazing! So much alive and warm :) I'm a smart guy, but as soon as I build a game that has all the basic elements . . .I get lost in the jungle of the code. So I started reading about design patterns. Well, my friend. You're the first one that I can follow! And even understand to that point that I can really see what you drew on your whiteboard as beautiful! Please keep making such simple videos and stop for so many explanations! :) :) :) Thank you man! p.s. Headfirst book sounds like a thing for me Love from Croatia!
@galtals
@galtals 5 жыл бұрын
great sound effects. the "boop" sound is to die for.
@felixjost8206
@felixjost8206 Жыл бұрын
Thank you so much for your passionate work!
@nickeax
@nickeax Жыл бұрын
Great teaching and information. Thank you very much!
@Amine670
@Amine670 5 жыл бұрын
Good explanation of the concepte and theory of the State Design Pattern, when rarely found in KZbin. (y)
@semajxocliw
@semajxocliw 4 жыл бұрын
i literally love you for these videos
@user-ew9qv3zy1y
@user-ew9qv3zy1y 11 ай бұрын
Thank you so much for these videos!
@niclaskron3384
@niclaskron3384 5 жыл бұрын
This was amazing, I learned alot. Thank you Christopher :-)
@johnmcway6120
@johnmcway6120 Жыл бұрын
This channel is such a blessing. Thank you so very much Chris.
@davidsierra3300
@davidsierra3300 6 жыл бұрын
excellent video, you have the gift of teaching! subbed
@lyonyan
@lyonyan 5 жыл бұрын
Only 72 comments? Here one more to appreciate your hard work and effort!
@orenfarhan8584
@orenfarhan8584 6 жыл бұрын
Nice one, but I disagree with passing the gate reference. If the interface for a state declares that an action causes a state to generate a state (e.g return GateState), you can avoid passing references to the gate itself, and from your gate call the action on the state to return a new state, and assign it to your ivar locally. Other than that, I like this playlist. For each pattern, I created a swift playgrounds version for future reference. I wasn't aware I was using so many of them :) Keep up the great work!
@VictorCarvalhoTavernari
@VictorCarvalhoTavernari 4 жыл бұрын
Hi, Could you if possible share your playgrounds files? I loved your solution about how to create a new State, just returning a State on each function, but if you are doing an async request probably you have to wait this new state, so probably call a delegate like changeState is better for a reactive approach.
@SemyonKalyakulin
@SemyonKalyakulin Жыл бұрын
As I remember, he mentioned that possible solution before the coding part:)
@amirkhazama7464
@amirkhazama7464 Жыл бұрын
what if the action we wanna do actually does produce a result and returns it like for example the payOk should return the payment id or something ... in that case the return type could not be just the new state .... . . . . . . . maybe you could specify the first returned item to be the new state and the other results to be the other stuff you are expecting from the method ...
@catcat942
@catcat942 4 жыл бұрын
This was good, I learned alot. Thank you!
@jojojojo483
@jojojojo483 4 жыл бұрын
You are a great teacher!
@alfredoportocarrero8663
@alfredoportocarrero8663 3 жыл бұрын
The best explanation of this pattern in the internet still 2020
@EuanFR
@EuanFR 5 жыл бұрын
As suggested in some comments, I would rather return the next state to the gate, from the states "action" methods, something like "nextState = currentState.actionPerformed()" (instead of a void return)
@abhishekjain3527
@abhishekjain3527 4 жыл бұрын
That would be helpful if you are returning void but if you are returning some response then you cannot return state. There should be a signalling mechanism to change state i.e one state should signal the parent gate to change state. And for states there should be a factory that creates these states
@Wubwub772
@Wubwub772 Жыл бұрын
@@abhishekjain3527 ​ you should return the new state and use "signalling mechanisms" for "some response", not the other way around
@osamucamarques
@osamucamarques 2 жыл бұрын
Very good stuff. Thanks man!
@shanm4629
@shanm4629 3 жыл бұрын
Once again.. another Great Video . Kudos to you.
@user-mb6cn8zq4v
@user-mb6cn8zq4v 3 жыл бұрын
Now it`s all clear, thanks !
@sarastanway8861
@sarastanway8861 5 жыл бұрын
wonderful series!
@nikiforovpizza
@nikiforovpizza 6 жыл бұрын
Thank you, dude! Useful and comprehensible tutorial)
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Thanks! Im glad to hear! And thanks for watching :)
@mfelsheikh
@mfelsheikh 3 жыл бұрын
This is amazing, really great Thank you
@rohitashkumawat5646
@rohitashkumawat5646 Жыл бұрын
Best design pattern videos 🙌
@kalinkalin4543
@kalinkalin4543 6 жыл бұрын
last repetition before exam, great job :D thanks
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Glad to hear it helps :) Best of luck on the exam! :)
@tomaszb9668
@tomaszb9668 3 жыл бұрын
Really really good tutorial. Greetings from Poland:)
@chandankumarmishra336
@chandankumarmishra336 6 жыл бұрын
very nicely explained...thanks a ton for this :)
@ravisankarjampani213
@ravisankarjampani213 6 жыл бұрын
Simply Superb
@aladdinoscopy
@aladdinoscopy 3 жыл бұрын
looking fierce bro! Thanks, you explain very well. ….. 25 more minutes in and damn even more impressed. I subscribed, thanks for teaching,
@TeotoniodeCarvalho
@TeotoniodeCarvalho 3 жыл бұрын
Very useful and clear even for a soil scientist like me!
@kattakittaxr
@kattakittaxr 2 жыл бұрын
wow this is an amazing tutorial thanks man
@edcatmull9253
@edcatmull9253 2 жыл бұрын
Love this, thank you!
@Generally2310
@Generally2310 6 ай бұрын
Great work 👏
@spin851
@spin851 5 жыл бұрын
Great video and channel I like it very well
@susanmbernard
@susanmbernard 5 жыл бұрын
Super helpful~Thanks!
@saurabhmahal1354
@saurabhmahal1354 3 жыл бұрын
got a deep dive into it .
@turtla3606
@turtla3606 2 жыл бұрын
Amazing! Thanks man!
@vinokanthvelu2660
@vinokanthvelu2660 5 жыл бұрын
Hey Chris. Thanks for these invaluable content. One request. Could you please do a video on Interpreter design pattern? Thanks mate.
@DavidBeharL
@DavidBeharL 3 жыл бұрын
I like It a lot, a bit longer than expected, but perfectly understood, this is a pattern very used in React, but this video is very useful to use It better
@user-ug8qc6tr6b
@user-ug8qc6tr6b 6 жыл бұрын
brilliant content!
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Thank you very much. I’m glad you appreciate it 😊
@loggoggles
@loggoggles Жыл бұрын
Thanks!
@MrChezzwizz
@MrChezzwizz 5 жыл бұрын
Thank you for your explanation. It was especially useful to hear about state diagrams and to see them used in the explanation of the UML. Your method of repetition seems to really help link your different parts together. I did have one question that I may attempt to experiment with myself and that is why a concrete state object wasn't returned from the action/message handler methods and used to set a reference in the context?
@miracaknar9549
@miracaknar9549 4 жыл бұрын
I will be your patreon if you start making videos again, you have my word.
@tofahub
@tofahub 5 жыл бұрын
Your videos are amazing. I enjoyed every bit of them. There is not a lot of good tutorials on advanced OOP on KZbin. Can you please consider making some?
@bbabak2
@bbabak2 3 жыл бұрын
Thanks a ton!
@GavinKimpson
@GavinKimpson 6 ай бұрын
I like this video will check your other videos for sure
@sweetteddy390
@sweetteddy390 2 жыл бұрын
Thank you so much for the wonderful explanation Chris!! Looking forward to more design pattern videos from you... for Builder/FlyWeight/ChainOfResponsibility/Memento/Mediator/Visitor may be? :)
@meratube007
@meratube007 6 жыл бұрын
Helpful ! thanks
@campanileLabs
@campanileLabs 3 жыл бұрын
Thanks alot
@javieralexandervictoriabal636
@javieralexandervictoriabal636 3 жыл бұрын
Eres muy grande!!! muchas gracias!!!!
@kushagr0123
@kushagr0123 5 жыл бұрын
Thanks a lot.
@bakyayita
@bakyayita 2 жыл бұрын
Much appreciated 👏🏽👏🏽👏🏽👏🏽👏🏽👏🏽👏🏽
@professorfontanez
@professorfontanez 4 жыл бұрын
Regardless of mutability, I would not store a Context (Gate) reference on all States. That creates a stronger bind between the Context and the State than simply using the context with needed (and then discard). With this in mind, I would simply pass the Context to each of the State interface methods so that the concrete State could then use the context to set the new (current) state.
@riteshtyagi5439
@riteshtyagi5439 6 жыл бұрын
Thank you your gateness
@avimehenwal
@avimehenwal 3 жыл бұрын
Wow! this is a jewel :) I would be using state pattern with my upcoming project and this video explains everything on topic. Excellent video. Keep the great work up (Y) I would like to hear your opinions on Inversion of Control and Dependency Inversion principle from SOLID. I am super confused between these two and can seem to make distinction between them. They look same to me
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
Question of the day: Have any examples of where you successfully used the state pattern?
@MarlyssonSilva
@MarlyssonSilva 6 жыл бұрын
I think that I've used it in a functionality where I manage a events system where there are subscription of people to participate... and the subscription have state : open, running and closed... where depends on your state some objects will be handled of different ways.
@lifescience2050
@lifescience2050 6 жыл бұрын
I developed a POS (point of sale) cashier app using the state pattern, seems the only practical choice. Your video is good and refreshing, our support developers definitely should go through this video before reading the POS code.
@pascalampere6098
@pascalampere6098 6 жыл бұрын
Used it in a VR app, where the Input of the User needed to cause different things to happen depending on the current state.
@user-ug8qc6tr6b
@user-ug8qc6tr6b 6 жыл бұрын
I build simple 2d game on JS. Decide to implement player state via state pattern. State like `idle`, `jumping` etc. By the way game examples is often easer to understand, when you explaining programming concepts. There is one interesting book, which I read recently "game programming patterns", maybe you will like it
@konradkudzia28
@konradkudzia28 6 жыл бұрын
Games. AI.
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 3 жыл бұрын
amazing. you rule!!!!
@olivermeyer3963
@olivermeyer3963 4 жыл бұрын
Hi, many thanks for the video I' ve learned a lot, appreciate that. My question or maybe suggestion, would you consider to change the names, to turn the names of the states e.g. OpenGateState => GateStateOpen, ClosedGateState => GateStateClosed etc. because int this way it's even more clear that they belong together.
@kareemjeiroudi1964
@kareemjeiroudi1964 4 жыл бұрын
I really like the idea that sometimes I don't get it the first, but then he tries to rephrase what he's saying or puts in a different way or with a different example, and then it starts to make sense to me. That's a lot of effort in explaining. He should become a professor or something.
@ch1l3no
@ch1l3no 3 жыл бұрын
Really nice job! Subscribing :D
@lesvideosgaming6910
@lesvideosgaming6910 3 жыл бұрын
Thanks you :)
@deathangel908
@deathangel908 5 жыл бұрын
It's great how you can describe things on the desk, but I guess the coding part can be done in textEditor or smth. With splitscreen so every class would be visible to a viewer at the same moment of time. The code would be much cleaner and readable thus. Means = more understandable
@pascalampere6098
@pascalampere6098 6 жыл бұрын
Random thought after you read the definition from the book at minute 38: Apart from the reactions to transition messages there could be a lot of other stuff being done differently depending on state. So maybe that is why they wrote that the object will appear to change its class? Obviously, the state needs to be able to deal with all potential incoming messages but apart from that it is pretty free-form regarding its capabilities, right?
@theisegeberg
@theisegeberg 6 жыл бұрын
Dang! This is the best of ALL the videos so far! I really thought I just knew this pattern inside out... and still the devil is in the detail... I'm saddened that it doesn't have more views, ALL developers should be forced to watch this :)
@kareemjeiroudi1964
@kareemjeiroudi1964 4 жыл бұрын
I was thinking the same thing. He makes things ten times easier to understand. And I also think that all developers out there must watch this design patterns series.
@VexingCode
@VexingCode 6 жыл бұрын
THANKS!
@ChristopherOkhravi
@ChristopherOkhravi 6 жыл бұрын
You're very welcome :) Thank you for watching :)
@kgck15
@kgck15 4 жыл бұрын
Really aweaome way of explaining concepts. More than that tge passion you show is tremendoua. Thanks for sharing uour knowledge. One question i had was ...why is pay part of gate class after paymentbdoes not happen on a gate. Having payok makes sense but not pay. Isnt it?
@thomastesson9399
@thomastesson9399 2 жыл бұрын
Hi Christopher, great videos and playlist. It helps me a lot to appropriate design patterns. About the State Pattern, it kinda looks like the Strategy Pattern as each state has its own logic, right? I would define the State Pattern as an evoled Strategy Pattern. Do you agree? Do you consider make a new video in this playlist to explain the difference(s) between these two? Thanks again :)
@noorafshanaz9092
@noorafshanaz9092 8 ай бұрын
Wow super ❤
@Mayukick
@Mayukick Жыл бұрын
Great video! I have been struggling to understand State Pattern but you made it really clear! I’m not very sure but the sample code you provided seems to be impossible to instantiate (apologies if I’m wrong) The reason is that the Gate class requires GateState object in the constructor while GateState requires Gate object in its constructor. It looks like circular reference, would it be possible to instantiate? (I’m gonna test it out when I’m available)
@shaileshchotoe
@shaileshchotoe 18 күн бұрын
great content, used to watch your videos years back, and now again. i noticed a small mistake but its not a big detail: in 7:10 u mention that if youre in the openstate and you receive a payOk message you stay in the Openstate, but in 58:11 youre giving an example for when youre in the openstate and you receive a payOk you close the gate. i think you accidently overlooked it
@MrRicharddaniel
@MrRicharddaniel 5 жыл бұрын
Hi will this video help someone new to redux understand the redux pattern ? I have been learning react from some time now and just like everyone else, jumping into redux which is confusing me... would the state pattern help ? Thanks for the great videos Christopher :)
@abhishekjain3527
@abhishekjain3527 4 жыл бұрын
Also how does it apply to multithreaded application as each thread could request the gate but since we are changing the state, All the threads has to wait for the processing thread
@user-po3lq7xc7n
@user-po3lq7xc7n 3 жыл бұрын
Hi Christopher, first thanks for making this series. I actually have questions regarding state pattern around 1:11:15. I see that whenever you change state you initiated a new state. I think for the same gate, if it opens, closes, and repeat, it should reuse the existing state. Am I wrong? I don’t understand the potential benefit of countinuous instantiation. Any light shed on my confusion would be appreciated.
@shakirrasheedkhankhattak9052
@shakirrasheedkhankhattak9052 5 жыл бұрын
Hi, such a great videos, really great step, salutation for this step. I have a question. Q - What about the GUARDS of the transition? such as events or actions on how to implement it.
@MichaelKire
@MichaelKire 3 жыл бұрын
Shakir Rasheed Khan Khattak I know this might be late, but think of code as being coded as the “happy path”. There can never be a false state. So if something happens that isnt allowed to happen, you throw an exception.
@khaloui3736
@khaloui3736 Жыл бұрын
Hi Christopher, first thanks for your explanations it helps a lot. I did not check the other comments, then I will give you my question (4 years later ^_^') Each time a state is changed by a handler by the changeState method. And through this method a new instance of State object is created. So here is the point: how the older state instance is deleted ? I suppose it depends of the languague we use but in some examples, a static instance is used
Null Object Pattern - Design Patterns (ep 18)
28:46
Christopher Okhravi
Рет қаралды 61 М.
Заметили?
00:11
Double Bubble
Рет қаралды 3,5 МЛН
Китайка и Пчелка 4 серия😂😆
00:19
KITAYKA
Рет қаралды 3,5 МЛН
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 2,7 МЛН
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 126 М.
Iterator Pattern - Design Patterns (ep 16)
1:37:25
Christopher Okhravi
Рет қаралды 92 М.
Google system design interview: Design Spotify (with ex-Google EM)
42:13
IGotAnOffer: Engineering
Рет қаралды 987 М.
Covariance and Contravariance
13:31
Christopher Okhravi
Рет қаралды 10 М.
Observer Pattern - Design Patterns (ep 2)
49:47
Christopher Okhravi
Рет қаралды 554 М.
When Microsoft Violated Liskov Substitution Principle in .NET
18:16
Christopher Okhravi
Рет қаралды 31 М.