title
Observer Design Pattern

description
Get the Code: http://goo.gl/EYGnQ Best Design Patterns Book : http://goo.gl/W0wyie MY UDEMY COURSES ARE 87.5% OFF TIL July 16th ($9.99) https://www.udemy.com/ ➡️ Python Data Science Series for $9.99 : Highest Rated & Largest Python Udemy Course + 56 Hrs + 200 Videos + Data Science https://bit.ly/Master_Python_35 ➡️ New C++ Programming Bootcamp Series for $9.99 : Over 23 Hrs + 53 Videos + Quizzes + Graded Assignments + New Videos Every Month https://bit.ly/C_Course_35 Welcome to my Observer Design Pattern Tutorial. I cover a lot in this tutorial including the Observer pattern, how to use it with threads and much more. The Observer pattern is a software design pattern in which an object, called the subject (Publisher), maintains a list of its dependents, called observers (Subscribers), and notifies them automatically of any state changes, usually by calling one of their methods.

detail
{'title': 'Observer Design Pattern', 'heatmap': [{'end': 69.602, 'start': 35.803, 'weight': 0.728}, {'end': 257.002, 'start': 186.063, 'weight': 0.847}, {'end': 301.079, 'start': 267.308, 'weight': 0.824}, {'end': 419.147, 'start': 389.436, 'weight': 0.996}, {'end': 475.974, 'start': 431.087, 'weight': 0.718}, {'end': 569.484, 'start': 521.419, 'weight': 0.709}, {'end': 623.162, 'start': 591.294, 'weight': 0.834}], 'summary': 'Covers the implementation of observer pattern in java, including loose coupling benefits, uml diagram representation, updating multiple objects, and using interfaces to create observer and subject classes. it also demonstrates adding, deleting, and notifying observers, implementing stock observer pattern with real-time price updates for ibm, apple, and google stocks using threads, and automating price changes with pausing functionality and generating random numbers.', 'chapters': [{'end': 284.983, 'segs': [{'end': 60.156, 'src': 'embed', 'start': 35.803, 'weight': 0, 'content': [{'end': 45.549, 'text': "So for example, Let's say we have a subject or publisher object that is going to represent thousands of individual stocks in the stock market.", 'start': 35.803, 'duration': 9.746}, {'end': 53.793, 'text': 'If you would need to send updates to multiple observers or subscribers, you would use the observer pattern to do that.', 'start': 45.769, 'duration': 8.024}, {'end': 60.156, 'text': 'So what is the benefit of the observer pattern? Well, like the strategy pattern, you get the benefits of loose coupling.', 'start': 54.093, 'duration': 6.063}], 'summary': 'Using the observer pattern for updating multiple subscribers provides the benefits of loose coupling.', 'duration': 24.353, 'max_score': 35.803, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT435803.jpg'}, {'end': 69.602, 'src': 'heatmap', 'start': 35.803, 'weight': 0.728, 'content': [{'end': 45.549, 'text': "So for example, Let's say we have a subject or publisher object that is going to represent thousands of individual stocks in the stock market.", 'start': 35.803, 'duration': 9.746}, {'end': 53.793, 'text': 'If you would need to send updates to multiple observers or subscribers, you would use the observer pattern to do that.', 'start': 45.769, 'duration': 8.024}, {'end': 60.156, 'text': 'So what is the benefit of the observer pattern? Well, like the strategy pattern, you get the benefits of loose coupling.', 'start': 54.093, 'duration': 6.063}, {'end': 65.739, 'text': "The subject or publisher doesn't need to know anything about the observers or subscribers.", 'start': 60.416, 'duration': 5.323}, {'end': 69.602, 'text': "I'm referring to them as two different things, because I think publisher makes more sense,", 'start': 65.899, 'duration': 3.703}], 'summary': 'Using the observer pattern allows sending updates to multiple subscribers for loose coupling.', 'duration': 33.799, 'max_score': 35.803, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT435803.jpg'}, {'end': 102.283, 'src': 'embed', 'start': 74.224, 'weight': 2, 'content': [{'end': 81.809, 'text': "The only negative of the observer pattern is the subject or publisher may send updates that don't matter to observers that are subscribed.", 'start': 74.224, 'duration': 7.585}, {'end': 86.692, 'text': 'And this is exactly what the observer pattern looks like using a UML diagram.', 'start': 82.429, 'duration': 4.263}, {'end': 95.779, 'text': "Over here, you have the subject and it is going to have these three methods defined, being register a new observer here's, an observer over here,", 'start': 86.872, 'duration': 8.907}, {'end': 102.283, 'text': "so it's going to have the capability to register new observers and in this situation we're going to save all the observers in an array list.", 'start': 95.779, 'duration': 6.504}], 'summary': 'Observer pattern may send irrelevant updates, demonstrated with uml diagram.', 'duration': 28.059, 'max_score': 74.224, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT474224.jpg'}, {'end': 153.14, 'src': 'embed', 'start': 112.191, 'weight': 3, 'content': [{'end': 121.279, 'text': "you're going to implement an interface for the main observer and then you're going to create classes that are going to implement this observer interface and in this situation,", 'start': 112.191, 'duration': 9.088}, {'end': 130.622, 'text': "we could say that this class down here is only going to be interested in the current price for IBM and this one's going to only be interested in the current price of Apple.", 'start': 121.279, 'duration': 9.343}, {'end': 135.766, 'text': 'But they are all going to use the update method to update the information inside of them.', 'start': 130.762, 'duration': 5.004}, {'end': 144.332, 'text': 'And the common definition for the observer pattern is a software design pattern in which an object called the subject maintains a list of its dependents,', 'start': 135.986, 'duration': 8.346}, {'end': 153.14, 'text': 'called observers, and notifies them automatically of any state changes that occur over here in subject, usually by calling one of their methods.', 'start': 144.332, 'duration': 8.808}], 'summary': 'Implement observer interface for subject and its dependents to notify of state changes.', 'duration': 40.949, 'max_score': 112.191, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4112191.jpg'}, {'end': 257.002, 'src': 'heatmap', 'start': 186.063, 'weight': 0.847, 'content': [{'end': 189.184, 'text': 'asked me to use the observer pattern with threads.', 'start': 186.063, 'duration': 3.121}, {'end': 192.966, 'text': "So first I'm going to present it in a simple way and then I'm going to present it using threads.", 'start': 189.504, 'duration': 3.462}, {'end': 197.612, 'text': "But you definitely don't need to use threads if you want to use the observer pattern.", 'start': 193.346, 'duration': 4.266}, {'end': 198.854, 'text': 'It has nothing to do with threads.', 'start': 197.632, 'duration': 1.222}, {'end': 199.715, 'text': 'And there you go.', 'start': 199.134, 'duration': 0.581}, {'end': 201.517, 'text': "There's your subject interface.", 'start': 199.915, 'duration': 1.602}, {'end': 206.344, 'text': "And now I'm going to come in here and use the observer.java interface or create it.", 'start': 201.838, 'duration': 4.506}, {'end': 208.146, 'text': "And it's also going to be simple, public.", 'start': 206.364, 'duration': 1.782}, {'end': 209.379, 'text': 'Even more simple.', 'start': 208.658, 'duration': 0.721}, {'end': 211.202, 'text': 'Interface Observer.', 'start': 209.66, 'duration': 1.542}, {'end': 212.604, 'text': "And then we're going to go public.", 'start': 211.542, 'duration': 1.062}, {'end': 213.986, 'text': 'Void Update.', 'start': 212.844, 'duration': 1.142}, {'end': 216.69, 'text': "And in this situation, I'm going to be playing around with stocks.", 'start': 214.307, 'duration': 2.383}, {'end': 218.112, 'text': "So I'm going to go IBM.", 'start': 216.77, 'duration': 1.342}, {'end': 220.115, 'text': "Price It's going to be a double.", 'start': 218.413, 'duration': 1.702}, {'end': 221.177, 'text': "Apple's price.", 'start': 220.436, 'duration': 0.741}, {'end': 222.96, 'text': "And that's not Apple spelled wrong.", 'start': 221.217, 'duration': 1.743}, {'end': 224.282, 'text': 'That is their stock symbol.', 'start': 222.98, 'duration': 1.302}, {'end': 229.843, 'text': "And let's say that we're also going to pass updates in regards to Google stock price.", 'start': 224.822, 'duration': 5.021}, {'end': 230.524, 'text': 'There you go.', 'start': 230.083, 'duration': 0.441}, {'end': 231.044, 'text': 'All done.', 'start': 230.684, 'duration': 0.36}, {'end': 231.884, 'text': "That's all set up.", 'start': 231.164, 'duration': 0.72}, {'end': 236.585, 'text': "So now I'm going to create another one of these guys called stockgrabber.java.", 'start': 232.084, 'duration': 4.501}, {'end': 239.686, 'text': 'And it is going to implement the subject interface.', 'start': 236.825, 'duration': 2.861}, {'end': 246.928, 'text': "So we're going to go public class stockgrabber implements subject, which is the interface we just created.", 'start': 240.046, 'duration': 6.882}, {'end': 249.297, 'text': "And then it's going to give me an error message.", 'start': 247.256, 'duration': 2.041}, {'end': 254.32, 'text': "And if I zoom in here, it's going to say the type stock grabber must implement the inherited abstract methods.", 'start': 249.317, 'duration': 5.003}, {'end': 255.261, 'text': "I'm going to say sure.", 'start': 254.4, 'duration': 0.861}, {'end': 257.002, 'text': "So that's going to save me a whole bunch of time.", 'start': 255.441, 'duration': 1.561}], 'summary': 'Demonstrated observer pattern with threads, using stock prices as an example.', 'duration': 70.939, 'max_score': 186.063, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4186063.jpg'}, {'end': 261.945, 'src': 'embed', 'start': 230.684, 'weight': 5, 'content': [{'end': 231.044, 'text': 'All done.', 'start': 230.684, 'duration': 0.36}, {'end': 231.884, 'text': "That's all set up.", 'start': 231.164, 'duration': 0.72}, {'end': 236.585, 'text': "So now I'm going to create another one of these guys called stockgrabber.java.", 'start': 232.084, 'duration': 4.501}, {'end': 239.686, 'text': 'And it is going to implement the subject interface.', 'start': 236.825, 'duration': 2.861}, {'end': 246.928, 'text': "So we're going to go public class stockgrabber implements subject, which is the interface we just created.", 'start': 240.046, 'duration': 6.882}, {'end': 249.297, 'text': "And then it's going to give me an error message.", 'start': 247.256, 'duration': 2.041}, {'end': 254.32, 'text': "And if I zoom in here, it's going to say the type stock grabber must implement the inherited abstract methods.", 'start': 249.317, 'duration': 5.003}, {'end': 255.261, 'text': "I'm going to say sure.", 'start': 254.4, 'duration': 0.861}, {'end': 257.002, 'text': "So that's going to save me a whole bunch of time.", 'start': 255.441, 'duration': 1.561}, {'end': 258.423, 'text': "And now I'm going to come in here.", 'start': 257.242, 'duration': 1.181}, {'end': 261.945, 'text': "Remember I said I'm going to store all of my observers in an array list.", 'start': 258.463, 'duration': 3.482}], 'summary': 'Creating stockgrabber.java implementing subject interface.', 'duration': 31.261, 'max_score': 230.684, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4230684.jpg'}], 'start': 0.185, 'title': 'Observer pattern implementation', 'summary': 'Covers the observer pattern, its benefits of loose coupling, and its uml diagram representation, with a focus on updating multiple objects, and implementing in java using interfaces to create observer and subject classes, and the usage of the update method.', 'chapters': [{'end': 112.191, 'start': 0.185, 'title': 'Observer pattern tutorial', 'summary': 'Covers the observer pattern, explaining its use in updating multiple objects, its benefits of loose coupling, and its uml diagram representation, with a focus on the capability to register new observers, unregister, and notify the observers of any changes.', 'duration': 112.006, 'highlights': ['The observer pattern is used when you need many other objects to receive an update when another object changes, such as representing thousands of individual stocks in the stock market.', 'The benefit of the observer pattern is the loose coupling between the subject or publisher and the observers or subscribers.', "The UML diagram representation of the observer pattern includes the subject's methods to register new observers, unregister, and notify the observers of any changes."]}, {'end': 284.983, 'start': 112.191, 'title': 'Implementing observer pattern in java', 'summary': 'Discusses implementing the observer pattern in java, emphasizing the use of interfaces to create observer and subject classes, and the usage of the update method to handle state changes and notifications.', 'duration': 172.792, 'highlights': ['The observer pattern is a software design pattern in which an object called the subject maintains a list of its dependents, called observers, and notifies them automatically of any state changes that occur, usually by calling their update method.', 'The subject interface is created to handle adding, deleting, and updating all the observers, and the observer interface contains the update method to handle information updates for specific stocks like IBM, Apple, and Google.', 'The stockgrabber class implements the subject interface, uses an ArrayList to store observers, and defines current prices for different stocks to be tracked and updated.']}], 'duration': 284.798, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4185.jpg', 'highlights': ['The observer pattern is used when you need many other objects to receive an update when another object changes, such as representing thousands of individual stocks in the stock market.', 'The benefit of the observer pattern is the loose coupling between the subject or publisher and the observers or subscribers.', "The UML diagram representation of the observer pattern includes the subject's methods to register new observers, unregister, and notify the observers of any changes.", 'The observer pattern is a software design pattern in which an object called the subject maintains a list of its dependents, called observers, and notifies them automatically of any state changes that occur, usually by calling their update method.', 'The subject interface is created to handle adding, deleting, and updating all the observers, and the observer interface contains the update method to handle information updates for specific stocks like IBM, Apple, and Google.', 'The stockgrabber class implements the subject interface, uses an ArrayList to store observers, and defines current prices for different stocks to be tracked and updated.']}, {'end': 664.04, 'segs': [{'end': 419.147, 'src': 'heatmap', 'start': 365.802, 'weight': 0, 'content': [{'end': 372.786, 'text': 'So that is going to delete observers from my array list so that I will no longer send them messages because that would just be silly.', 'start': 365.802, 'duration': 6.984}, {'end': 378.43, 'text': 'And then notify observer is going to cycle through all the observers and notify them of any price changes that occur.', 'start': 373.047, 'duration': 5.383}, {'end': 381.051, 'text': "And I'm going to put this in an enhanced for loop.", 'start': 378.73, 'duration': 2.321}, {'end': 383.633, 'text': "So we're going to go observer, which is the type.", 'start': 381.252, 'duration': 2.381}, {'end': 386.675, 'text': 'Observer is going to be the temporary holding cell.', 'start': 383.893, 'duration': 2.782}, {'end': 389.136, 'text': 'And observers is going to be the array list.', 'start': 387.034, 'duration': 2.102}, {'end': 394.341, 'text': "And then I just got to go observer and call the update method that I'm going to create here in a second.", 'start': 389.436, 'duration': 4.905}, {'end': 397.364, 'text': 'And it automatically is going to put all that information in there for me.', 'start': 394.561, 'duration': 2.803}, {'end': 398.545, 'text': 'So that saves me some time.', 'start': 397.464, 'duration': 1.081}, {'end': 399.126, 'text': "That's awesome.", 'start': 398.585, 'duration': 0.541}, {'end': 402.99, 'text': "Then I'm going to create a couple other methods that I'm going to use later on.", 'start': 399.386, 'duration': 3.604}, {'end': 405.552, 'text': 'And all the code is available underneath this video in a link.', 'start': 403.13, 'duration': 2.422}, {'end': 409.538, 'text': "So go get it if you actually want to read the comments because it's heavily commented.", 'start': 405.894, 'duration': 3.644}, {'end': 410.218, 'text': 'All right,', 'start': 409.878, 'duration': 0.34}, {'end': 416.745, 'text': "so I'm going to give them the option to change prices for all the different stocks and then notify observers of any other changes that occur.", 'start': 410.218, 'duration': 6.527}, {'end': 419.147, 'text': 'So double new IBM price.', 'start': 416.925, 'duration': 2.222}], 'summary': 'Deleting observers from array list, notifying of price changes, using enhanced for loop, creating update method, providing option to change prices and notify observers.', 'duration': 33.324, 'max_score': 365.802, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4365802.jpg'}, {'end': 479.676, 'src': 'heatmap', 'start': 431.087, 'weight': 1, 'content': [{'end': 435.452, 'text': 'So this is going to notify all the observers after the price has been changed for IBM.', 'start': 431.087, 'duration': 4.365}, {'end': 439.496, 'text': "And then we're just going to do exactly the same thing for all the other stocks that we're going to be monitoring.", 'start': 435.612, 'duration': 3.884}, {'end': 446.68, 'text': 'And this could easily be turned into a real world application that gets real stocks and all that stuff without any problem at all.', 'start': 439.716, 'duration': 6.964}, {'end': 450.062, 'text': "Whenever I implement threads, it's going to make it even easier to do that.", 'start': 446.86, 'duration': 3.202}, {'end': 455.705, 'text': "And then here we're just going to go AAPL, which is going to represent Apple, and then notify the observers.", 'start': 450.182, 'duration': 5.523}, {'end': 458.566, 'text': "And here we're going to do the same thing for Google.", 'start': 455.785, 'duration': 2.781}, {'end': 461.168, 'text': "So if you didn't know the stock symbol for these, now you do.", 'start': 458.787, 'duration': 2.381}, {'end': 462.731, 'text': "And there we are, we're done.", 'start': 461.548, 'duration': 1.183}, {'end': 464.114, 'text': 'We just created that guy.', 'start': 462.911, 'duration': 1.203}, {'end': 470.108, 'text': 'So now we have to create stock observer, which is going to implement the observer interface that we just created.', 'start': 464.295, 'duration': 5.813}, {'end': 471.152, 'text': 'Pretty simple.', 'start': 470.592, 'duration': 0.56}, {'end': 475.974, 'text': 'Just go public, class, implements, the observer, interface.', 'start': 471.272, 'duration': 4.702}, {'end': 477.655, 'text': "There's going to be a whole bunch of these.", 'start': 476.354, 'duration': 1.301}, {'end': 479.676, 'text': "And it's public, not pubic.", 'start': 477.675, 'duration': 2.001}], 'summary': 'Creating a notification system for stock price changes with potential for real-world application and use of threads.', 'duration': 62.751, 'max_score': 431.087, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4431087.jpg'}, {'end': 569.484, 'src': 'heatmap', 'start': 521.419, 'weight': 0.709, 'content': [{'end': 527.644, 'text': "And then I'm going to give each individual observer object that has created a special observer ID.", 'start': 521.419, 'duration': 6.225}, {'end': 529.345, 'text': "And that's not going to be static of course.", 'start': 527.804, 'duration': 1.541}, {'end': 533.846, 'text': 'and then so I can make references to the stock grabber object.', 'start': 529.625, 'duration': 4.221}, {'end': 561.414, 'text': "I'm gonna go private and I'm gonna call it subject and refer to it as the subject interface that it implements and that's just gonna provide me access to that guy so that I can run different methods public the constructor and it's gonna be passed a reference to the current stock grabber object and I'm just going to store the reference of that stock grabber object in our own personal stock grabber object that's assigned to this observer.", 'start': 533.846, 'duration': 27.568}, {'end': 565.399, 'text': "And then I'm also going to give each observer its own ID.", 'start': 561.715, 'duration': 3.684}, {'end': 569.484, 'text': "And I'm going to make sure that I increment it like that, which is just going to add one.", 'start': 565.419, 'duration': 4.065}], 'summary': 'Creating individual observer objects with special ids and interface access.', 'duration': 48.065, 'max_score': 521.419, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4521419.jpg'}, {'end': 623.162, 'src': 'heatmap', 'start': 591.294, 'weight': 0.834, 'content': [{'end': 597.161, 'text': 'And this is the reason why we needed our own stock grabber object that references the main guy.', 'start': 591.294, 'duration': 5.867}, {'end': 604.63, 'text': "Because we need to register or add our new observer that we just created to stock grabber's array list.", 'start': 597.181, 'duration': 7.449}, {'end': 610.096, 'text': 'And then we get into the class that we always are going to have to create here, which is update.', 'start': 604.93, 'duration': 5.166}, {'end': 611.618, 'text': "And let's just jump up here.", 'start': 610.356, 'duration': 1.262}, {'end': 613.798, 'text': "And I'm just going to paste that inside of there.", 'start': 612.137, 'duration': 1.661}, {'end': 617.34, 'text': "That's equal to IBM price that's been passed over.", 'start': 613.818, 'duration': 3.522}, {'end': 619.421, 'text': "And then in this situation I'm going to go this.", 'start': 617.36, 'duration': 2.061}, {'end': 623.162, 'text': "Which is a reference to the object or the observer that we're playing with here.", 'start': 619.481, 'duration': 3.681}], 'summary': 'Creating a stock grabber object and adding a new observer to its array list for ibm price update.', 'duration': 31.868, 'max_score': 591.294, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4591294.jpg'}], 'start': 285.323, 'title': 'Implementing observer pattern in java', 'summary': 'Demonstrates the implementation of the observer pattern in java, including adding and deleting observers from an arraylist, and notifying observers of price changes using an enhanced for loop. it also explains the creation of methods to change stock prices and notify observers, with the potential to be turned into a real-world application, and the creation of stock observer classes to monitor stock prices and register new observers.', 'chapters': [{'end': 399.126, 'start': 285.323, 'title': 'Implementing observer pattern in java', 'summary': 'Demonstrates the implementation of the observer pattern in java, including adding and deleting observers from an arraylist, and notifying observers of price changes using an enhanced for loop.', 'duration': 113.803, 'highlights': ['Notifying observers of price changes using an enhanced for loop The program cycles through all the observers to notify them of any price changes, using an enhanced for loop, saving time and enhancing efficiency.', 'Deleting observers from the array list The method demonstrates the process of deleting observers from the array list, ensuring that they will no longer receive messages, and thereby improving the functionality of the program.', 'Adding new observers to the array list The process involves adding a new observer to the array list, improving the functionality and flexibility of the program.']}, {'end': 664.04, 'start': 399.386, 'title': 'Stock price monitoring system', 'summary': 'Explains the creation of methods to change stock prices and notify observers, with the potential to be turned into a real-world application, and the creation of stock observer classes to monitor stock prices and register new observers.', 'duration': 264.654, 'highlights': ['Methods created to change stock prices and notify observers, with potential real-world application and thread implementation for easier stock monitoring.', 'Creation of stock observer classes to monitor stock prices and register new observers with unique IDs.', 'Implementation of update method to print the updated stock prices for all observers.']}], 'duration': 378.717, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4285323.jpg', 'highlights': ['Notifying observers of price changes using an enhanced for loop The program cycles through all the observers to notify them of any price changes, using an enhanced for loop, saving time and enhancing efficiency.', 'Methods created to change stock prices and notify observers, with potential real-world application and thread implementation for easier stock monitoring.', 'Creation of stock observer classes to monitor stock prices and register new observers with unique IDs.', 'Deleting observers from the array list The method demonstrates the process of deleting observers from the array list, ensuring that they will no longer receive messages, and thereby improving the functionality of the program.', 'Adding new observers to the array list The process involves adding a new observer to the array list, improving the functionality and flexibility of the program.', 'Implementation of update method to print the updated stock prices for all observers.']}, {'end': 987.323, 'segs': [{'end': 785.439, 'src': 'embed', 'start': 760.631, 'weight': 0, 'content': [{'end': 766.613, 'text': "I just actually checked them And if I file, save that and execute, you can see here new observer's been created right there.", 'start': 760.631, 'duration': 5.982}, {'end': 768.354, 'text': 'And there is the observer, one.', 'start': 766.954, 'duration': 1.4}, {'end': 773.375, 'text': "And then as it changes the prices, each time there's a price change, this observer's notified.", 'start': 768.374, 'duration': 5.001}, {'end': 775.656, 'text': "So when IBM's price changes, there you go.", 'start': 773.436, 'duration': 2.22}, {'end': 778.137, 'text': "And there's Apple, which hasn't been changed yet.", 'start': 775.856, 'duration': 2.281}, {'end': 780.938, 'text': 'But then Apple is changed, and so forth and so on.', 'start': 778.397, 'duration': 2.541}, {'end': 782.598, 'text': 'However, it looks like we have an error here.', 'start': 781.138, 'duration': 1.46}, {'end': 783.979, 'text': "So let's jump over and see what it is.", 'start': 782.618, 'duration': 1.361}, {'end': 785.439, 'text': 'Ah, I forgot to print it out.', 'start': 784.359, 'duration': 1.08}], 'summary': 'Creating new observer to monitor price changes for ibm and apple, with an error in the process.', 'duration': 24.808, 'max_score': 760.631, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4760631.jpg'}, {'end': 848.848, 'src': 'embed', 'start': 821.129, 'weight': 1, 'content': [{'end': 825.611, 'text': 'And you can see one by one, they are automatically changed right there on the fly.', 'start': 821.129, 'duration': 4.482}, {'end': 826.732, 'text': "So that's pretty cool.", 'start': 825.911, 'duration': 0.821}, {'end': 833.736, 'text': 'You can also see that if I go stock, grabber, unregister, observer, one for example.', 'start': 826.992, 'duration': 6.744}, {'end': 834.556, 'text': "I'll save it.", 'start': 834.136, 'duration': 0.42}, {'end': 835.538, 'text': 'And execute it.', 'start': 834.898, 'duration': 0.64}, {'end': 838.921, 'text': 'Boom And you can see right there, observer 1 is deleted.', 'start': 835.779, 'duration': 3.142}, {'end': 841.883, 'text': "And after it's deleted, it no longer receives updates.", 'start': 839.121, 'duration': 2.762}, {'end': 842.744, 'text': "So that's pretty cool.", 'start': 842.083, 'duration': 0.661}, {'end': 848.848, 'text': "So now I'm going to show you how to use threads with an observer pattern, which is a pretty common thing to occur.", 'start': 843.064, 'duration': 5.784}], 'summary': 'Demonstration of automatic changes in observer pattern with thread usage.', 'duration': 27.719, 'max_score': 821.129, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4821129.jpg'}, {'end': 904.516, 'src': 'embed', 'start': 864.109, 'weight': 2, 'content': [{'end': 867.591, 'text': "Okay, so I know I need to format the decimal as you're going to see here in a second.", 'start': 864.109, 'duration': 3.482}, {'end': 870.894, 'text': 'So this is totally improved, but I should be able to do it.', 'start': 867.631, 'duration': 3.263}, {'end': 873.356, 'text': 'And this is going to allow you to use threads.', 'start': 871.194, 'duration': 2.162}, {'end': 875.918, 'text': "So we're going to implement runnable.", 'start': 873.876, 'duration': 2.042}, {'end': 881.062, 'text': 'And this is just going to allow me to use threads without having to waste my extends,', 'start': 876.318, 'duration': 4.744}, {'end': 884.604, 'text': "so that I'll be able to use more than one class using the runnable interface.", 'start': 881.062, 'duration': 3.542}, {'end': 885.465, 'text': "So that's pretty cool.", 'start': 884.624, 'duration': 0.841}, {'end': 888.168, 'text': "And then I'm going to go Well actually let me show you something here.", 'start': 885.745, 'duration': 2.423}, {'end': 896.279, 'text': "Let's say that I wanted to set it so that the thread is updated based off of a start time that I define.", 'start': 888.709, 'duration': 7.57}, {'end': 897.501, 'text': 'I could do it this way.', 'start': 896.56, 'duration': 0.941}, {'end': 902.428, 'text': "I'm going to have my stock which is going to be the name for the stock and I'm also going to have a price.", 'start': 897.721, 'duration': 4.707}, {'end': 904.516, 'text': "That's what each of these threads is going to have.", 'start': 902.895, 'duration': 1.621}], 'summary': 'Improving thread implementation to use runnable interface for multiple classes.', 'duration': 40.407, 'max_score': 864.109, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4864109.jpg'}], 'start': 664.04, 'title': 'Implementing and using stock observer pattern with threads', 'summary': 'Covers implementing stock observer pattern with classes and objects, showcasing registration, update, and deletion of observers, with real-time price updates for ibm, apple, and google stocks. it also focuses on using threads with an observer pattern to implement the runnable interface, allowing multiple classes to use threads, and demonstrates creating a stock updater based on a defined start time and price.', 'chapters': [{'end': 842.744, 'start': 664.04, 'title': 'Implementing stock observer pattern', 'summary': 'Covers the implementation of the stock observer pattern using classes and objects, with the observer being notified of price changes, showcasing the registration, update, and deletion of observers, with real-time price updates for ibm, apple, and google stocks.', 'duration': 178.704, 'highlights': ['The chapter emphasizes the use of classes and objects to implement the stock observer pattern, with the observer being notified of real-time price changes for IBM, Apple, and Google stocks.', 'It covers the registration, update, and deletion of observers, demonstrating the dynamic nature of the observer pattern.', 'Real-time price updates for IBM, Apple, and Google stocks are showcased, with the observer being notified of each price change.']}, {'end': 987.323, 'start': 843.064, 'title': 'Using threads with observer pattern', 'summary': 'Focuses on using threads with an observer pattern to implement the runnable interface, allowing for multiple classes to use threads, and demonstrates creating a stock updater based on a defined start time and price.', 'duration': 144.259, 'highlights': ['The chapter demonstrates implementing the runnable interface to use threads without having to waste extends, enabling multiple classes to use the runnable interface.', 'It showcases creating a stock updater based on a defined start time and price, allowing for efficient and controlled thread execution.', 'The chapter reviews the concept of decimal formatting and its usage, highlighting its importance in the context of the demonstration.']}], 'duration': 323.283, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4664040.jpg', 'highlights': ['The chapter emphasizes the use of classes and objects to implement the stock observer pattern, with real-time price updates for IBM, Apple, and Google stocks.', 'It covers the registration, update, and deletion of observers, demonstrating the dynamic nature of the observer pattern.', 'The chapter demonstrates implementing the runnable interface to use threads without having to waste extends, enabling multiple classes to use the runnable interface.', 'It showcases creating a stock updater based on a defined start time and price, allowing for efficient and controlled thread execution.']}, {'end': 1345.519, 'segs': [{'end': 1052.861, 'src': 'embed', 'start': 987.804, 'weight': 0, 'content': [{'end': 992.836, 'text': "And let's say that I want to create new prices or change the prices 20 times.", 'start': 987.804, 'duration': 5.032}, {'end': 994.097, 'text': "Well, that's what that's going to do.", 'start': 992.936, 'duration': 1.161}, {'end': 1000.4, 'text': "Now, since I'm using this interface to pause it for two seconds, that's what that guy does.", 'start': 994.317, 'duration': 6.083}, {'end': 1005.802, 'text': "It's going to pause it so that it waits two seconds before it executes the code that I have down below.", 'start': 1000.76, 'duration': 5.042}, {'end': 1010.405, 'text': 'And right here, if you wanted to make this change This is where you would do that.', 'start': 1006.023, 'duration': 4.382}, {'end': 1015.787, 'text': "You'd do something like paste that in there and then multiply this and then go in and change that to 1000.", 'start': 1010.465, 'duration': 5.322}, {'end': 1021.909, 'text': "That would allow you to change how long the program waits before it executes, which I've shown many times before.", 'start': 1015.787, 'duration': 6.122}, {'end': 1023.23, 'text': "And then I'm going to cheat here.", 'start': 1022.19, 'duration': 1.04}, {'end': 1026.892, 'text': 'Catch Interrupted Exception E.', 'start': 1023.43, 'duration': 3.462}, {'end': 1029.093, 'text': "And I'm just going to cheat, like I said, and just put that in there.", 'start': 1026.892, 'duration': 2.201}, {'end': 1029.752, 'text': "I know that's bad.", 'start': 1029.113, 'duration': 0.639}, {'end': 1032.674, 'text': "And then I'm going to create a double random number.", 'start': 1030.032, 'duration': 2.642}, {'end': 1034.795, 'text': "And I'm going to say something like random.", 'start': 1033.114, 'duration': 1.681}, {'end': 1044.794, 'text': "Because what I want to do here with this is I want to have it kick out a value for random that's going to be between negative 3 cents and positive 3 cents.", 'start': 1035.145, 'duration': 9.649}, {'end': 1049.458, 'text': "Well, to do that, you're going to multiply it times what you want to create here.", 'start': 1045.174, 'duration': 4.284}, {'end': 1051.64, 'text': "So that's going to be 0.06.", 'start': 1049.698, 'duration': 1.942}, {'end': 1052.861, 'text': 'And then the result of that.', 'start': 1051.64, 'duration': 1.221}], 'summary': 'The transcript discusses changing prices, pausing execution, and creating random numbers within a specific range.', 'duration': 65.057, 'max_score': 987.804, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4987804.jpg'}, {'end': 1274.299, 'src': 'embed', 'start': 1243.076, 'weight': 4, 'content': [{'end': 1246.797, 'text': "Paste Like I said, it's going to create three threads using the runnable interface.", 'start': 1243.076, 'duration': 3.721}, {'end': 1253.863, 'text': "And I'm using the runnable interface so I don't waste my one and only extendable class option that we all get at birth.", 'start': 1247.418, 'duration': 6.445}, {'end': 1260.208, 'text': "So there's AAPL, Google, and then I'm going to pass it the same price as it originally had.", 'start': 1254.283, 'duration': 5.925}, {'end': 1266.012, 'text': 'And then, of course, after we create these threads, we have to call for the code and run to execute.', 'start': 1260.548, 'duration': 5.464}, {'end': 1267.934, 'text': 'So thread get IBM.', 'start': 1266.353, 'duration': 1.581}, {'end': 1274.299, 'text': "Start And that's all this line of code does is it says, hey, whatever is going on inside of the run method, run it.", 'start': 1268.514, 'duration': 5.785}], 'summary': 'Creating three threads using the runnable interface with specific stock prices, then executing the run method.', 'duration': 31.223, 'max_score': 1243.076, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT41243076.jpg'}], 'start': 987.804, 'title': 'Automating price changes and generating random numbers', 'summary': 'Discusses automating price changes with a pausing functionality, enabling 20 price changes with a 2-second delay and setting a waiting time of 1000 milliseconds. it also covers generating random numbers with specific constraints, implementing threads for stock price updates, and practical coding techniques for real-time observation of stock prices.', 'chapters': [{'end': 1029.752, 'start': 987.804, 'title': 'Automating price changes with pausing functionality', 'summary': 'Discusses automating price changes using a pausing functionality that allows for a delay of two seconds before executing the code, enabling the user to make 20 price changes and set a waiting time of 1000 milliseconds.', 'duration': 41.948, 'highlights': ['The pausing functionality allows for a delay of two seconds before executing the code, facilitating the creation or alteration of prices 20 times.', 'The user can set the waiting time to 1000 milliseconds, enabling a customizable delay before the code execution.', 'The code includes a catch for Interrupted Exception E, allowing for error handling and continuity of the automation process.']}, {'end': 1345.519, 'start': 1030.032, 'title': 'Code tutorial: generating random numbers', 'summary': 'Discusses generating random numbers with specific constraints and implementing threads for stock price updates, with an emphasis on practical coding techniques and real-time observation of stock prices.', 'duration': 315.487, 'highlights': ['The chapter explains how to create a double random number with specific constraints, such as a value between negative 3 cents and positive 3 cents, achieved by multiplying it by 0.06 and subtracting 0.03.', 'The code tutorial demonstrates the implementation of threads for updating stock prices, using the runnable interface to avoid wasting the extendable class option and ensuring real-time observation and automatic updates of stock prices.', 'The author provides a shoutout to a viewer working on a non-sponsored tutorial for creating social networks and outlines the criteria for shoutouts in future videos, emphasizing the unsponsored and free nature of the shoutouts.']}], 'duration': 357.715, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/wiQdrH2YpT4/pics/wiQdrH2YpT4987804.jpg', 'highlights': ['The pausing functionality allows for a delay of two seconds before executing the code, facilitating the creation or alteration of prices 20 times.', 'The user can set the waiting time to 1000 milliseconds, enabling a customizable delay before the code execution.', 'The code includes a catch for Interrupted Exception E, allowing for error handling and continuity of the automation process.', 'The chapter explains how to create a double random number with specific constraints, such as a value between negative 3 cents and positive 3 cents, achieved by multiplying it by 0.06 and subtracting 0.03.', 'The code tutorial demonstrates the implementation of threads for updating stock prices, using the runnable interface to avoid wasting the extendable class option and ensuring real-time observation and automatic updates of stock prices.']}], 'highlights': ['The observer pattern is used when you need many other objects to receive an update when another object changes, such as representing thousands of individual stocks in the stock market.', 'The benefit of the observer pattern is the loose coupling between the subject or publisher and the observers or subscribers.', "The UML diagram representation of the observer pattern includes the subject's methods to register new observers, unregister, and notify the observers of any changes.", 'The observer pattern is a software design pattern in which an object called the subject maintains a list of its dependents, called observers, and notifies them automatically of any state changes that occur, usually by calling their update method.', 'The subject interface is created to handle adding, deleting, and updating all the observers, and the observer interface contains the update method to handle information updates for specific stocks like IBM, Apple, and Google.', 'The stockgrabber class implements the subject interface, uses an ArrayList to store observers, and defines current prices for different stocks to be tracked and updated.', 'Notifying observers of price changes using an enhanced for loop The program cycles through all the observers to notify them of any price changes, using an enhanced for loop, saving time and enhancing efficiency.', 'Methods created to change stock prices and notify observers, with potential real-world application and thread implementation for easier stock monitoring.', 'Creation of stock observer classes to monitor stock prices and register new observers with unique IDs.', 'Deleting observers from the array list The method demonstrates the process of deleting observers from the array list, ensuring that they will no longer receive messages, and thereby improving the functionality of the program.', 'Adding new observers to the array list The process involves adding a new observer to the array list, improving the functionality and flexibility of the program.', 'Implementation of update method to print the updated stock prices for all observers.', 'The chapter emphasizes the use of classes and objects to implement the stock observer pattern, with real-time price updates for IBM, Apple, and Google stocks.', 'It covers the registration, update, and deletion of observers, demonstrating the dynamic nature of the observer pattern.', 'The chapter demonstrates implementing the runnable interface to use threads without having to waste extends, enabling multiple classes to use the runnable interface.', 'It showcases creating a stock updater based on a defined start time and price, allowing for efficient and controlled thread execution.', 'The pausing functionality allows for a delay of two seconds before executing the code, facilitating the creation or alteration of prices 20 times.', 'The user can set the waiting time to 1000 milliseconds, enabling a customizable delay before the code execution.', 'The code includes a catch for Interrupted Exception E, allowing for error handling and continuity of the automation process.', 'The chapter explains how to create a double random number with specific constraints, such as a value between negative 3 cents and positive 3 cents, achieved by multiplying it by 0.06 and subtracting 0.03.', 'The code tutorial demonstrates the implementation of threads for updating stock prices, using the runnable interface to avoid wasting the extendable class option and ensuring real-time observation and automatic updates of stock prices.']}