Hi, in this video we have covered Observer design patter out of many design pattern which is asked in Low level system design interview. ➡️ Become a Member: / @conceptandcoding
Пікірлер: 474
@NeverGiveUp186 Жыл бұрын
This is the first LLD video where I saw real coding example.. and not just theory. Great work man!! Keep it up !!
@ConceptandCoding Жыл бұрын
Thanks 🙏
@motivational_journey__ Жыл бұрын
@@ConceptandCoding please share notes of videos
@yogeshshukla60975 ай бұрын
@@ConceptandCodingplease can you share github or notes that is the only lacking point
@vortexgamingtv010 ай бұрын
at 32:41 , the reason for not notifying again is that, in the implementation of obj.setStockCount(newStockCount) { stockCount = stockCount + newStockCount } not { stockCount = newStockCount }
@runtime379 Жыл бұрын
As a fresher , Started learning LLD from today. Enjoying the concept .so simple explanation and easy to understand Thanks bhaiya
@ConceptandCoding Жыл бұрын
Thank you
@adhrit14268 ай бұрын
For the notify function in observable concrete class, we can call the update of observer and send the current object in parameter. In the observer class, we don't necessarily have to use instance of operator in conditionals, if getData() is there in the observable interface, then we can directly use observable.getData() and it is fine. No need for constructor injection as well
@swayamprakashsahoo90025 ай бұрын
Exactly. This code will be lengthy when observer will observe multiple observable objects. So better to pass observable object through update parameter.
@msingla1355 ай бұрын
Was thinking the same. Why not pass the object of current concrete class to update instead of interface.
@ankitgoyal85565 ай бұрын
My though process: Assume you are passing object in update() Method: update(Object obj) 1) Check if this obj is null or not 2) Check if this is object of Observable or not 3) Then have to perform typeCasting, multiple checks if multiple child of ObservableInterface. Simply we can't do obj.getData() because obj can be null or of any other type. Better use constructor injection approach. I might be wrong.
@omkarjoshi37505 ай бұрын
@@ankitgoyal8556 good point, what if we pass null. solution-> you can return without doing anything with just one if condition. 2. Why do we need to check if object is of type Observable or not, if we are expecting a variable of type Observable then how can other type can come. if someone tries this, then code will give compilation error 3. type casting is not needed. we can directly call obj.getData()
@utkarshjaiswal72244 ай бұрын
According to my understanding, we don't need both the things neither constructor injection nor passing the current object, We are already adding the observer in iphone observable, why we need to differentiate it
@krutikadave4534Ай бұрын
Recently i started reading Head First II edition, I come back to your examples after going through each chapter. Thanks a lot for knowledge. It's really helpful.
@parasmyname784 Жыл бұрын
Just brilliant, You are giving us true insight into enterprise level coding,, thanks a lot
@ConceptandCoding Жыл бұрын
Thanks
@agunnik8 Жыл бұрын
Happy to be here before this channel blows up. Keep up the quality content.
@ConceptandCoding Жыл бұрын
welcome
@gyandeepdigra84619 ай бұрын
bought Gaurav Sen's course but you explain better than him. I saw only 1 video from his playlist and will watch all ur videos. Keep up bro..
@ConceptandCoding2 жыл бұрын
Hi Guys, how was the explanation? Please let me know where i can improve. like voice speed and clarity, depth of topic detail, handwriting, example taken etc.
@neha60002 жыл бұрын
Aap ne bahoot achha video banaya hain
@gurdevrana59172 жыл бұрын
It was really amazing. Thanks a lot. Keep up the good work.
@ConceptandCoding2 жыл бұрын
@@gurdevrana5917 thanks a ton
@aashishgoyal14362 жыл бұрын
top notch
@abhaytiwari16152 жыл бұрын
Insanely awesome explanation!! Loved it.
@omtiwari23873 ай бұрын
Very nice explaination. In the Observable concrete class, you should first update the stocks value and then call update for the observers. Reason: It might happen that the update method in Observer has something to do with the number of stocks currently available. It will get the old value not the updated one.
@srijonroy70849 ай бұрын
Simple and brilliant explanation. Particularly good for those who is revising and have some idea
@ConceptandCoding9 ай бұрын
Thanks
@mahabaligowda6925Ай бұрын
Hi Shrayansh, Your amazing man, I have reviewed Java and DP's. Now i am fan of you. you make concept simple, understandable and moreover easy to remember, Thanks for your hard work man. you have great future. For sure we see more video's going forward.
@snehilsinha4689 Жыл бұрын
I think that in the setStockCount() method, we should do stockCount = newStockAdded instead of stockCount+=newStockAdded since let's say we want to make the stock as 0 as in 32:42, the stockCount will stay 10 itself as 10+0 = 10. That's the reason why it didn't notify second time. Please correct me if I am mistaken somewhere while understanding this. Thanks.
@dhanbahadurchhettri2712 Жыл бұрын
Yes I was also thinking why it didn't print twice
@wul_frik Жыл бұрын
I think it's better if we keep the setStockCount() as such and add another method addStockCount() which will notify subscribers. Another thing is we have to add the stocks before notifying the subscribers if we want to get the new stockCount from the observable in update() method.
@tanmaya2421 Жыл бұрын
stockCount+=newStockAdded is correct. Let's say stockcount = 5, then we add 100 new stocks, so stockcount becomes 105. But if we use stockCount = newStockAdded, then it will give incorrect stock count (in this case 100 instead of 105 ).
@ishaansrivastav5732 Жыл бұрын
@@tanmaya2421 True, but then for the example he gave when he set stock count to 0, he should have reduced the stock count with -10
@ranitganai27257 ай бұрын
Yes , it should have printed twice but it didn't because stockCount is set to 0 for once only, after that stockCount is getting updated everytime resulting notify method not getting executed.
@danishmichael69532 ай бұрын
An Observer can register with multiple Observables. If we use constructor injection, then we are limited to only one Observable implementation which is usually not the case.
@vipintripathi536211 күн бұрын
Yeah, I think same.
@handlenotavailable538 Жыл бұрын
just joined the channel for lld, hld and java videos, great content bro, worth the money 😃
@ConceptandCoding Жыл бұрын
:) thanks a lot
@dhvanilvadher13565 ай бұрын
Thank you @Shreyansh ! I have never found a better Design pattern video.
@ConceptandCoding5 ай бұрын
thanks
@deepakkedia38812 жыл бұрын
nicely explained Shrayansh. Hope to get more videos on LLD.
@mannusharma32282 ай бұрын
Hats off to your explanation buddy.... big fan of your teaching 😊
@GlynesDsouza-zb8pq Жыл бұрын
Too good.... This level of depth in knowledge covered with such simplicity..... Its phenomenal. Thank you so much and keep the good work up
@ConceptandCoding Жыл бұрын
Thank you
@eshwarsai50273 ай бұрын
Man! You are really killing in teaching the concepts❤️.
@ayushijain29112 жыл бұрын
One of the best explanation on youtube. Thanks
@ConceptandCoding2 жыл бұрын
thanks Ayushi 🙂
@harshmangal65765 ай бұрын
Amazing simple explanation i have never seen such a simple explanation keep it up 😊
@ConceptandCoding5 ай бұрын
thanks
@namanjain248811 ай бұрын
observal -> state changes. observer -> state changes of observable observed by observer make there interface where there can be many observer but single observable and make there classes In observable class u will make a list of observer , u will add observer, remove objserver , notify all observer , and change the state of data or get the state of data.
@abirpaul90278 ай бұрын
the best teacher for lld
@ConceptandCoding8 ай бұрын
Thanks 🙏
@ParomitaDeSarkar Жыл бұрын
Thankyou for this video. The mixture of the question and the explanation pattern together, will help me to remember this kind of scenario well. Thankyou once again!
@ConceptandCoding Жыл бұрын
Thanks 🙏
@Seekplay883 Жыл бұрын
Simple and crispy explanation, hats-off to you
@ConceptandCoding Жыл бұрын
Thanks a lot 🙏
@shatrudhankumar78246 ай бұрын
Why i found your video so late ?Anyway, You make things easier then what people used to complex it.
@ConceptandCoding6 ай бұрын
thanks for the feedback
@kapilgyanchandani4 ай бұрын
Very good explanation with examples, Thanks a lot for such videos.
@mohitladia Жыл бұрын
Loved the real-time scenario
@ConceptandCoding Жыл бұрын
Thanks
@nishantkumar6116 Жыл бұрын
Very Nice Explanation. Please keep on adding new videos on these topics
@ConceptandCoding Жыл бұрын
thank you
@anirbandutta22662 ай бұрын
Well explained, you gave a good clarity of the concept, easy to remember + revise.
@abhaytiwari16152 жыл бұрын
Hi Shrayansh, wouldn't there be need of initializing many objects if there are many obervable for a single observer...dependency injection in method update will be better right? THen both of them become loosely coupled, and anyway since the method are from interface we can call it using the interface argument......eg could be like 1 user can call notify on multiple items..so in that case it becomes m:n relation.. pls correct me if i am missing something
@soumalyasahoo2664 Жыл бұрын
can you give another example where the observer has multiple observable? In this case i think instead of having a observable object inside the observer , we might need to have concrete objects as task that the observer will perform after geting the data from the observable(s) might depend on the type of the observable. For example: if the observable is temperature increase , the observer will lower the temperature , and if another observable is item in stock notification , the observer will place a order for that item. Or if we follow what you said in this video , where i dont have to check the type of observable , then i might need to make differnt types of observer Example : TempObserver, StockObserver
@sourabhchoudhary7289 Жыл бұрын
Not sure if you are talking about an observer having multiple observables at the same time(eg, the App have footballScoreObservable, cricketScoreObservable, etc) or an observer having multiple observable at diff times(eg, we switch to a different page so now we will have a footballScoreObservable and another page will have cricketScoreObservable. Both footballScoreObservable and cricketScoreObservable will implement a common interface, so it's like a strategy pattern where we select Observable at runtime.
@adhrit14268 ай бұрын
If you have a observer subscribed to multiple observables(eg weather station and stock market), then it's better not to use constructor injection. Just add this observer to both WeatherStation and Stock market and whenever any one of them changes, the observer will be notified. If you use constructor injection, then that means you have kind of hardwired which type of observable this user wants, so multiple subscription for same observer object will fail.
@anuragv400 Жыл бұрын
Great explanation man! It was really helpful
@ConceptandCoding Жыл бұрын
Thanks
@ishanpatil6294 Жыл бұрын
Question 1 : In case of more then one observable in a single observer, wouldn't you still have to check which observable called the update method? resulting in some if/else again inside update(). Question 2 : If we don't send the data in update(), won't the update logic loose on some data in case of race condition? (say temperature updates few times in a row, and since instead of passing the temperature value we are passing observable object which will have updated data always.)
@abhishekmahajan17 Жыл бұрын
It will be better if we send the observable object in update method. You have found the loopholes
@aravindkumarn1776 Жыл бұрын
Buddy it's easy to add caption for old videos. Just edit your video in KZfaq studio and select English in caption drop-down and then click save/submit changes. It will take sometimes to add caption automatically to your video.
@ConceptandCoding Жыл бұрын
No buddy it's not working, hindi to English caption is not working. It want me to type each line which I am saying in hindi. There are certain language for which auto caption is available and hindi is not one of it.
@aravindkumarn1776 Жыл бұрын
@@ConceptandCoding Oh okay buddy. If possible could you please create playlists for spring boot if possible. You really good teacher nice content creator that's why I am giving my suggestion
@mahendrapatidar7416 Жыл бұрын
Bhai kya explain krte ho yr, maja aa gya. I love you.
@ConceptandCoding Жыл бұрын
Thank you 🙂
@dheeraj5531 Жыл бұрын
Nicely explained everything ❤
@ConceptandCoding Жыл бұрын
Thanks
@sagar16917 ай бұрын
Again very well explained , And yes it will be nice if you explain Implementation With PropertyChangeListener which is another way to implement this.
@jaymanik Жыл бұрын
Thank you for the detailed video. Very good explaination.
@ConceptandCoding Жыл бұрын
Thanks
@vishalsharma8432 Жыл бұрын
Hi Shrayansh, thanku for this amazing tutorial.
@ConceptandCoding Жыл бұрын
Thanks 👍
@shardulsant4726 Жыл бұрын
Why can't you pass 'this' (instance of WSObservable) in the update instead of constructor injection. You can then call whatever methods on that like you did with constructor instantiated object.
@umangmalhotra1222 Жыл бұрын
While notifying observers, we should do the same in an asynchronous manner.
@jinendrajain7672 Жыл бұрын
Greate work, Huge respect for you bro.
@ConceptandCoding Жыл бұрын
Thanks
@sameer9368 Жыл бұрын
Awesome Explanation♥
@neha60002 жыл бұрын
Bahoot hi achha explanation
@sameerchoudhary85906 ай бұрын
Very crisp and clear explanation.
@vikashkumarchaurasia1299 Жыл бұрын
🎉🎉🎉 perfect explaination
@aksharbrahm46182 ай бұрын
It was good ..one suggestion .. Koi ek hi language me poora video banaiye ..Kabhi kabhi aap english me switch ho jate ho ..HIndi me hi rakhiye
@mohitthakur55712 жыл бұрын
Good stuff Shrayansh. Keep them coming
@ConceptandCoding2 жыл бұрын
thank you
@dileepkumareduvaka4864Ай бұрын
excellent work man, this is really good, telling theoretically is one thing, but writing actual code is another thing. But i have a doubt, could you suggest anything to C++ people, because syntax may differ and its difficult.
@aadhaarbhatia27596 ай бұрын
Great one!! I could not understand the part where it was mentioned that we would have had to use "instanceof" if we were not doing constructor injection. Please add some clarity on that part. Some example would be great!!
@paritoshdadhich295411 ай бұрын
Thanks for the wonderful explanation
@rajdave7357 Жыл бұрын
Sir sach bolu Maja aagaya ❤❤❤❤
@ConceptandCoding Жыл бұрын
Thank you
@gauravsharma4532 Жыл бұрын
Perfect , to the point explanation. Keep posting vedios👏
@ConceptandCoding Жыл бұрын
Thanks
@nikhilupadhyay2199 Жыл бұрын
Sir I am just starting to watching your video. Please Sir make more it'll help us
@ConceptandCoding Жыл бұрын
Sure, yes lot of videos already uploaded and next will come on Sunday
@shubhamagarwal14342 ай бұрын
Very well explained...awsome!!!
@ashwani6360Ай бұрын
we should use set to store all the observers in the observable class
@jagritbhupal5836Ай бұрын
Amazing video, Thank you!
@patrisrikanth7 ай бұрын
Awesome Explanation ...
@ConceptandCoding7 ай бұрын
thanks
@satish79314 ай бұрын
Thanks for the video!! Having both Setdata Getdata methods inside Observable class seem to violate Single responsibility principle. Now this class is responsible for both notifying as well as managing the data. May be better to seperate the data managing part to seperate interface and take it as input to observable class
@geekydanish59902 жыл бұрын
I think thats the perfect example of how a High Level design model such as pub-sub is translated into a low level Observer pattern, I think for each hld there must exisits some corresponding lld pattern that's my hypothesis 😬
@ConceptandCoding2 жыл бұрын
this is a topic of discussion 😊😊 i cannot say as i am not sure
@saivasanth8819 Жыл бұрын
Hi Danish, there is a slight difference here, In the observer pattern, the observable and observer know each other, but in the pub-sub model, the publisher and consumer will not know each other, they will communicate through the queue. So, this is where both will get vary, but the concept of notifying is same, hope you got the clarity :)
@harshinredzone Жыл бұрын
in my opinion, pub sub is still observer. It's only one level abstraction. Instead of them interacting directly, they have agents to take care of it in pub sub.
@LifeDude2 ай бұрын
Kind of same. Where pub sub messages are preserved where as here fire and forgot no events are kept
@myaccount09011975Ай бұрын
Thanks Shrayahsh for this video. In case of multiple customers registering for 1000 products on Amazon, I believe we will not create multiple observers for each product right. How can we accommodate this requirement? How will it work in case of Distributed setup where entire scenario is handled by different microservices. We need a distributed Notification mechanism, right? I believe pubs/subs or event messages may be good option here.
@prakashshindalkar69592 жыл бұрын
very good explanation. Thank you
@ConceptandCoding2 жыл бұрын
thank you
@nishanthmekala1409 Жыл бұрын
Your videos are awesome. But I would like to know the below things 1. which one we should start first hld or lld? 2. In what way we should learn hld and lld? 3. How to practice these and gain hands on experiene? 4. Is it necessary to take a course after watching your videos? 5. Any order, you would reccomment to follow? Please clear my doubts Shreyansh.
@ConceptandCoding Жыл бұрын
Both can be learn in parallel. If exp less than 2yr. LLD can be done first else both can be done in parallel
@aashishgoyal14362 жыл бұрын
very nicely explained.Keep it up
@ConceptandCoding2 жыл бұрын
thank you
@Newbie789 Жыл бұрын
great explanation, thank you so much for making this kind of video.
@ConceptandCoding Жыл бұрын
Thank you
@kanchankatkar522613 күн бұрын
You explained very well, thanks for your content. just one thing can I get code repo to go through it. or can I download it from somewhere?
@terminator8397 Жыл бұрын
In case of multiple observables, do you end up writing different update methods in the observer class. Checking instance of gets replaced with new method strongly tied to one of the observable. Am I missing something here?
@rpatil1169 Жыл бұрын
Great Explanation
@ConceptandCoding Жыл бұрын
Thanks
@iWontFakeIt6 ай бұрын
excellent explanation!
@ConceptandCoding6 ай бұрын
thanks
@swayamprakashsahoo90022 ай бұрын
Interviewer : Now scale it for multiple products
@prashantgupta6160 Жыл бұрын
Hey, Shreyansh, nicely explained, but I do have one question. Q1. we are designing this notify me service for amazon, amazon has lot of products, will each product be creating one concrete observable? or there will be single observable that keeps the record of subscribers for all the product in the form of map of arrays where key is product id and array is list of subscribers and when writing notify it will take product id and notify the respective subscriber. Q2. we are saying concrete observer will have instance of concreate observable, what to do, if I want to observe multiple products from Amazon?
@sourabhchoudhary7289 Жыл бұрын
we are saying concrete observers will have instances of concrete observable, what to do if I want to observe multiple products from Amazon? I think here sending the observable object to the observer.update(obj) will be a good option as multiple observables can send the update event and then we have to figure out which instance called it using instanceof. As even if maintain a list of observables in observer it will not solve our problem as we still have to figure out which observable triggered the update event. hope it make sense, and correct me if I am wrong :)
@anantsingh2004 Жыл бұрын
in the update method firstly the count should be set and then if (count != 0) notifySubscribers can be called.
@AdityaSingh-pj7kw2 ай бұрын
Hey Shrayansh Can you please provide access to the notes and code used in the video? Keep up the great work!!
@pawan0209 Жыл бұрын
Great explanation 👍🏻
@ConceptandCoding Жыл бұрын
Thank you
@naveenam6322 Жыл бұрын
It definitely helps if this is taught in English. who doesn't know Hindi
@ConceptandCoding Жыл бұрын
I have covered it's English version Live LLD Sessions: kzfaq.info/sun/PL6W8uoQQ2c63ODkc0LVNiZtVX4vrsO3iO
@naveenam6322 Жыл бұрын
@@ConceptandCoding thank you
@anirudhsingh78327 ай бұрын
Good Video. Thanks man.
@mohammadkaif8143 Жыл бұрын
Awesome Content
@ConceptandCoding Жыл бұрын
Thanks for
@user-cy8fj7xx1n4 ай бұрын
Great video
@ripanpramanick425 Жыл бұрын
We can take List in the WSObservable Interface as whenever we will be adding data from our concrete class we can add object to final list as we are not reassaigning new list object but only afding object to final list
@adhrit14268 ай бұрын
Even if you do so, the list will be public, static and final like you said. But the think is if we have two observables, like WeatherStation and CricketScoreUpdate, then whenever you add something for weather station, it will reflect for cricket score update as well, which in most cases is not fine, since observable will have their own observers, they won't necessarily share observers. You add for observable 1, by default will get added to all the observables
@sunitajoshi902 Жыл бұрын
Great work man..
@ConceptandCoding Жыл бұрын
Thank you
@sahildadhich592 ай бұрын
very nice
@AnupSingh-hd5ck Жыл бұрын
I understand the observer pattern but what if the application goes down or somehow we lost the stored information(observers) ? in this scenerio how will get the data back ? of course we need to store these information in db. but if it`s in the db then what is the purpose of observer pattern ? we can simple query the db and do the stuff (querying again and again is not good approach ) so can you or anyone explain this to get better understanding about this.
@ravikumar-gp6ui Жыл бұрын
Amazing explanation. nice video
@ConceptandCoding Жыл бұрын
Glad you liked it
@AtharvaRao0104 Жыл бұрын
In the concrete observer, we inject concrete observable in the constructor so that we can get the updated state from this concrete observable when a notification comes. But I also think the concrete observer needs that observable to subscribe (register) itself. Right?
@shubhshah419211 ай бұрын
Yes
@user-ft6sh1wx6jАй бұрын
Second wale case if we do setStock(100) then it adds to previous count of 10 hence we are not seeing it twice
@muskan_bagrechaАй бұрын
Shouldn't we have a single observable class which can handle multiple products identified by their ID? Then we can pass this object to the observer and observer will check if it is not null then it can perform some action, so no need of contructor injection also. Please correct me if i am wrong.
@SyedaTabassum.23 күн бұрын
1. Can we consider Linkedin Job alert feature as Observer Design Pattern,? 2. Can we get code repository link for all these design patterns, would be helpfull for revision?
@engineer_jaatni Жыл бұрын
Really Helpful!
@ConceptandCoding Жыл бұрын
Thank you
@syedsheheryarumair973 ай бұрын
Very informative video! I have a question that suppose if my store has 100 products apart from iPhone. I would have to create 100 concrete classes for it?
@PrateekSaini6 ай бұрын
If we keep an instance of Observable in Observer then I can call setData also. It's better to use a Notification object and pass it to the update method. This Notification object will contain all the necessary information.
@bhavesh25shah2 ай бұрын
In the example, I can see that there is a dependency of Observer interface in Observable interface and vice versa. I don't understand one thing how the dependency will get resolved? Will it end up in cyclic dependency? Can you please help explaining it? Which object will get created first and how?
@weirdstrategist2 ай бұрын
a doubt here , can't this be solved by the following strategy : 1. Use a single table with a composite key (product_id, user_id) to store user subscriptions.The users will be added to based on the endpoint for notify users. 2. When stock becomes available, a Kafka event is triggered. 3. A dedicated service consumes Kafka events and queries the centralized table for users subscribed to the specific product. 4. Users are then notified based on a separate endpoint. Doesnt this eliminates the need for observer pattern here
@dhirajrana397Ай бұрын
For a observer having multiple obervers: List observableList, in update method how do we find which data in observer to be updated / what action to be performed ?
@dakshtaneja9189 Жыл бұрын
Hey I have a doubt here: if we are creating iphone object and passing it in the constructor of observer i.e - email or mobileAlert. then still it is not becoming that dynamic like in a system of 1000 products do we need to create 1000 objects of each product and then pass it in the observer constructor. Need to know how we can make it dynamic when the system is large or there are multiple products.
@newgusern7184 Жыл бұрын
Same doubt
@akshaymahajan96266 ай бұрын
very good
@ConceptandCoding6 ай бұрын
thanks
@Lucifer-dd1zn3 ай бұрын
Hey, lets say if there is a observer concrete class listening to 3 different observables, [video time : 12:55] 1. How will we inject 3 different objects of observables [for eg if a single customer says notify me for 3 different products at different times] in the observers class ? 2. Even if we can lets says we maintain a List in Observer, we still would need to go through all of them to know which one has actually changed. So how is Observer keeping an object / list of Observable/ Observables helping ? Basically whats the best solution in that case ?
@adarshdivya4883 Жыл бұрын
Hindi me zaada ache se samjh me aata hai humlog zaada ache se connect kar paate hai
@aditya.chavda Жыл бұрын
Wouldn’t it be better if you just pass the data directly from Observable as parameter to the update method of Observer? Cause having the object of Observable in a Observer is unnecessary I think. Wouldn’t having so also expose all the other methods (like add, remove, setData, etc) of the Observable to the Observer?
@ConceptandCoding Жыл бұрын
Yes we can. Let's understand what things we need to consider if we want to pass the data as parameters: - Scenario1: Pass all the different parameters which are required by Observer, but problem with that is, number of parameters size become big. - Scenario 2: Observer should expose the POJO, in which observable class fills the data and send. But problem with that is why Observable takes the responsibility to fill the pojo. - Scenario 3 : Observer have Observable object, problem with that is " which you raised" All we can go with different ways all has some pros and cons, and we can choose based on situation. Hope that clarifies