Wow. This video is 10 years old and still kinda relevant.
11 ปีที่แล้ว +2
Hi Jamie, Your tutorial is clear and very explicit. But I want to know more about this pattern: in Head First Design Patterns there is a complete section dedicated to this pattern but it is explain in Java, so I need to need if there are two equivalents to Observable class and Observer interface (java.util package)... is there? Thanks in advance for your response. ;) Regards from Bogotá (CO),
There is not. That is Java's way of making up for not having delegates. If you look at the Gang of Four, Java's implementation is very close to it. However, .NET cleaned this (often used) pattern up via delegates. It's a religious preference as to which one you use. Chaining delegates is an orthogonal feature. Look up Bruce Eckel's mp3 interview with Ander's on this topic. It is extremely enlightening.
TrainSignal is a class that contains a delegate and a method that invokes the delegate Car is a class that takes TrainSignal as a parameter Car assigns the TrainSignal Delegate to it's private function StopTheCar() In main you create a TrainSignal instance You pass the Instance of TrainSignal to many Instances of Car That way the delegate of TrainSignal references a chain of StopTheCar fcts When the fct HereComeTheTrain is invoked all the fct stored in the delegate will run...
//Observer pattern... dont know how to explain it. Watch this video again and again until you can express what is going on in words // A Delegate can reference a private method inside a class. // When you call that delegate the private method will run. This is very weird, but delegates are just compiler Aspartame
I watch the whole playlist and it's excellent. The explanations are great and helps me a lot.
This is an excellent demonstration of the observer pattern using delegates. Thank you!
omg, my ears!
Memo for me: No more wearing headphones, when listening to your classes O.O
lol :D
you are really a KING
Wow. This video is 10 years old and still kinda relevant.
Hi Jamie,
Your tutorial is clear and very explicit. But I want to know more about this pattern: in Head First Design Patterns there is a complete section dedicated to this pattern but it is explain in Java, so I need to need if there are two equivalents to Observable class and Observer interface (java.util package)... is there?
Thanks in advance for your response. ;)
Regards from Bogotá (CO),
This nailed it for me. Great content
There is not. That is Java's way of making up for not having delegates. If you look at the Gang of Four, Java's implementation is very close to it. However, .NET cleaned this (often used) pattern up via delegates. It's a religious preference as to which one you use. Chaining delegates is an orthogonal feature. Look up Bruce Eckel's mp3 interview with Ander's on this topic. It is extremely enlightening.
is the interview with Anders Hejlsberg? If it is I got the right audio then.
Yes. I believe there are two.
TrainSignal is a class that contains a delegate and a method that invokes the delegate
Car is a class that takes TrainSignal as a parameter
Car assigns the TrainSignal Delegate to it's private function StopTheCar()
In main you create a TrainSignal instance
You pass the Instance of TrainSignal to many Instances of Car
That way the delegate of TrainSignal references a chain of StopTheCar fcts
When the fct HereComeTheTrain is invoked all the fct stored in the delegate will run...
Nice and easy way rather than implementing IObservable of T. However how do you Unsubscribe a certain object?
//Observer pattern... dont know how to explain it. Watch this video again and again until you can express what is going on in words
// A Delegate can reference a private method inside a class.
// When you call that delegate the private method will run. This is very weird, but delegates are just compiler Aspartame
Straight to the point, I like your style JK 👍
THANK YOU !!!
All you want
@@JamieKingCS Can you make StopTheCar() method have parameters ?
The answer is yes: public Action TrainsAComing;
look like clasic events on c# :v
Jamie is great but c# syntax is terrible here. We subscribe to the event by adding to the delegate!
Great tutorial! Maybe don't speak so loud please? :)
Your computer/phone/tablet should have a volume control to handle things like this. Try turning yours down.