Dynamic Pricing & Payment Integration in BookMyShow! ๐ŸŽฌ๐Ÿ’ณ #lowleveldesign #codingintelugu

Devs in Progress ยท Beginner ยท๐Ÿ—๏ธ Systems Design & Architecture ยท1y ago

About this lesson

Join this channel to get access to perks: https://www.youtube.com/channel/UCT5ZpljzkT418SKoddQRrlg/join In today's members-only live session, weโ€™ll cover: ๐Ÿ”„ Strategy Pattern for dynamic pricing ๐Ÿญ Factory Pattern for flexible payment methods ๐Ÿ‘€ Observer Pattern for real-time notifications Learn practical system design with essential patterns! ๐Ÿš€

Full Transcript

hello me [Music] S what's your name you don't only one in this live right [Music] now hello hello [Music] everyone every respond so that I am I Audible hello hello hello yeah finally got some response [Music] [Music] hello should we start there's no response from anybody Sai can you please respond I'm audible should we start the [Music] live part three in building our bookm show application right so am uh I am audible right fine so let's let's go ahead and start so low level design of book discuss two parts finish one is the base where we covered all the models model classes and we wrote a booking service which is a Singleton class this service interact with all our model classes and user Behavior Sim we have booking service demo this is what we have discussed in part one now coming to part two part two book filtering feature and sorting feature Implement filtering we implemented two kinds of filters movie filter and Multiplex filter uh user you know if at all any user uses our application user will be able to filter based on the moving names and he'll also be able to uh filter based on Multiplex names feature extend features like gen feature price feat sorry genre filter price filter Etc movie filter and Multiplex filter we implemented using strategy design pattern me filters we implemented using decorator design pattern and similarly sorting we implemented using strategy design part sorting cheapest show SED so cheapest show first so when I was implementing this I thought every show unless every show has a different price this feature is you know is useless right soov two show first show and second show if red key price different we can sort them based on the cheapest to show first right so we'll be building today Dynamic feature features the pricing will differ early [Music] morning so this pricing Dynamic pricing Implement we'll be using strategy design pattern we are trying to implement or calculate the price of a show using different strategies peak season low we'll use Peak pricing strategy off peak off season L off pring strategy anniversary or maybe last year there was some day uh Indian movie day or International Movie day I don't remember it properly so Alan we you know they were offering tickets for 100 rupees IR respect of the seats and respect of the shows so alante cases occasion ke will be providing some discount on shows so situations different strategies us see how do we calculate the price of a show that you know that is what we are going to discuss first today okay so danam because we are using strategy design pattern again we know the steps uh we'll create a uh seate package called [Music] pricing because we are trying to implement this feature using strategy design pattern even last live discuss there are two important steps first we'll write an interface for the strategy interface need different concrete classes implement manager so manager is optional if you want to uh you know handle all your strategies using one single class you can write manager or else you can choose not to also direct strategies you can call it in your main method so let me just go ahead and first create an interface for pricing so pricing strategy low what is our method our method will be calculate the price for a show price this price is associated with show not the screens not the multiplexes or not the seats seats already separate uh you know prices only if you see in model and seat category silver 150 price gold 200 and platinum 250 is what we have already already uh assigned so this these prices which we are calculating using pricing strategy are associated with shows so we'll be calculating the price pretty sh key irres of what strategy we are using to price it we have a basic price right so let let me pass a base price in order to calculate the price for a show this will return double because base price the price dou here now the second step is let's write the concrete classes as we discussed let's start with Peak pricing strategy so in we'll be implementing our interface we have to implement so Implement based on this base price consider I want to increase its price by 20% so that's why I'm multiplying with 1.2 so this will return base price plus 20% of the base price because it's Peak pricing strategy I'm increasing the base price let's go for off peak this will also Implement our pricing strategy let me just implement the method base price because it's off seon 10% the so I'm multiplying the base price with 0.9 let's create another another concrete class called discount pricing strategy this will also Implement pricing strategy so what should we do discount let's directly reduce it to half right or also we can do we just multiply by on five both are same basically right now we have our pricing strategy defined now depending on the season admin should be able to uh change the pricing strategy for a particular show right so show CL show class Kelly instead of Simply you know writing a get uh writing an attribute called price let's write pricing strategy disc yeah yeah okay you want me to do that okay so okay let me just uh you know figure out the basics first and then we'll keep adding uh you know extra features uh so uh you know what Sai is saying is uh a discount pricing strategy low he wants me to take the percentage of you know uh discount percentage here right so our you know pricing strategy has only one method so [Music] whenever discount is taking two overlo we'll try to create two methods here so elu we'll have to implement both of them both the methods here so in that cases you can use abstract classes in those cases right so that's a little complicated design we'll have to uh you know digress from whatever we are discussing I'll come back to this okay so generally how how to answer your question Sai uh you know you can do method overloading and create a separate method in order to change the number of parameters in your method right so yeah coming back to our you know we just implemented a basic pricing strategy and then let me have a simple pricing strategy okay pricing strategy every you know method calculate price in all these pricing strategies are expecting a base price so base price the strategy that is that it is following right so private static [Music] it will be the same base price will not change depending on the object that you create or depending on the show that it is base price mether we are making some changes right so base price will be the same so I'm making it static final right now let me just create [Music] another let me call it get show price our show price depends on the pricing strategy that the admin is selecting while creating a show correct so pricing strategy 30 pricing strategy dot calculate price of I'll pass this base price so this is how you're calculating the price of a show this is a show class right so CL a particular logic execu that will be the price of your show so now let's see how where and you know how do we use this uh this particular show price now if you go to our booking service I'm cating the total price based on the selected seats so there are two things to keep in mind whenever I'm selecting a show we have to show to the user So currently how are we calculating total this Cate total price we just calculating the category price gold gold uh silver silver so select this SE I'm adding I'm doing the sum of each category for each seat I just have to add my show dot get show price so let me pass show also here consider you have show here and get show price two SE so each gold is 200es so 200 plus 200 400 return now I'm also adding the dynamic pricing that I introduced in the show show L show price is depending on the pricing strategy that the admin is selecting while creating the Show discount base price which which is 50 divided by 2 because we are multiplying with 0.5 it will the base price the price of that particular show which is following discount pricing strategy then base price 25 and we are adding that 25 to my total price or show your base price depend which you are calculating depending on the pricing strategies that the admin is selected you can apply that price on each seat that you selecting selected seats count or size two separate separ applying this you know the dynamic price that I'm having for a show so I hope this is clear so here when you're calculating the total price for a booking seats depending on the show also you price will [Music] change let's see there are some issues here let's try to fix them yeah I'll just pass it here right yeah so this is how you can Implement your Dynamic pricing for a particular show now because we are anywhere talking about pricing so payment and payment you're trying to book a ticket you'll first check if the seats are available if seats are available then you'll select them right you'll select them you'll Mark the seats as booked and then you'll select them and then you'll calculate the price total price right bot total price right creating a booking you go and pay finally before you know you're returning this booking you'll finally go and pay if the payment is successful e booking and object you'll make the payment status as successful else you'll make it as failed booking if I'm trying to create a booking and even if the payment fails I can in history locally I can go and check my bookings un failed payment failed bookings so I need to save it even if the irresp of the payment right so that is the basic idea so let's again you know let's start from scratch put know this is the base application that I have now my new requirement is that is given to me is integrate payment user should be able to pay and then book the ticket so again the same thing the most common use pattern strategy design pattern because payment there are again different ways credit card payment um PayPal n payment or net banking n payment right so for that let's create another package here called let's call it payment so we have done a lot of we implemented a lot of strategy design so I'll go a little quickly here interface create called payment strategy you can also let me know in the comments uh you know what you know what should I do next and I also you know strongly suggest all of you who is attending this live to go ahead and code along with me try to switch tabs and try to implement it then you'll be you know I think it'll be more exciting that way strategy Java CL payment strategy interface so I have to process the payment here for so let me just create process payment so am I'll be processing that payment right but what does this return this should return an object of type payment right so so before jumping into our strategy design pattern and implementing payment first we we have to check he payment strategy that will eventually interact with this model classes right so our model class we should have our payment uh you know payment class so can you please respond make this um you know live interactive the basic thing that we'll have is private string ID the ID to generate using uid and then private obviously basic thing that a payment uh class will have is uh the amount so double amount payment status yeah payment ID already this is the payment ID amount so payment fail success so that for that we need to have a enum right so just like we had um you know seat status or seat category or booking status let me have a enom for payment method and payment status so am status pending successful and fail successful is never used okay now let's create another [Music] enum payment method this will again have maybe credit card debit card net [Music] banking what else UPI maybe PayPal k i nank now once we have it let's go back to our payment and let's try to create attributes payment method payment method all again payment status and what is the time stamp when yeah correct payment as size suggesting payment time and date so let's me just write it local date [Music] time let's call it time stamp [Music] right Constructor as usid [Music] I just do ID generator gener ID so I think by default status we can change it to pending right initially when you create an object for payment it'll be uh pending the status will be pending right so let me just go ahead and create Setter methods for um payment state payment method and maybe amount let me just create get methods for everything done so now we have our base ready payment now let's go to our payment process payment and this will return once payment it will return return me whole payment object and that payment object will have payment ID amount payment status and when when did the payment occur right now what um so let's have uh for now uh for the sake of Simplicity just let's create a credit card payment form a credit card payment will Implement what it will Implement payment strategy because credit card is one of the strategies payment strategies now what this will do first in order to return a payment object this should return an object of payment payment stat and so let's let's make it am and then payment method do credit card because this credit card payment I'm passing credit card here generally time stamp we'll have to record it real time cty Let's do let's take the current time stamp for this time stamp so local dat time do now now once this is done here we have to check we actually call third party you know services like credit card here at this point of time he'll be calling you know SBI apis by passing this payment object and then attributes if SBA conf confirms that you know payment is successful or failed will be setting the payment status payment status consider if it is uh you know successful uh let me just update the payment status as successful when you you know attending your machine coding rounds you can write a separate function called uh mock payment processor and and you can randomly generate true or false or 90% cases L you can generate true and return true from that method 10% cases low you can uh return false and then that method will be returning false depending on that you'll be you know setting your payment status as failed even I'll Implement that uh I'll come back to that so return payment here my intention is to create a payment object call the third party API and simply return the payment object right so let's try to create another thing like let's say Paypal payment like credit card payment all Paypal payment all this will also Implement payment strategy go same we can just go here copy this paste it here okay crit card same we are just simulating our success but it depends on the third party apis whatever it returns depending on that we'll be doing the step right now if you remember what we discussed yesterday strategy pattern always go hand you know hands on hand with manager class apart from that it goes hands you know hand on hand with uh another pattern what is that pattern because we have multiple objects that we are creating here right so Paypal payment object if the payment strategy that is selected by the user is Paypal user credit card we have to create an object for this so different objects creation we can follow Factor design pattern Factor design pattern us we can create a separate class called uh you know payment uh we can create a class called payment strategy Factory which tells you this is the class responsible for creating objects for payment strategies and different payment strategies say credit card and Paypal payment right I just uh let me just finish uh calling this or using these strategy design uh strategy classes and then later as an improvement I'll be adding this Factory uh class here so let's go to our booking service booking related or booking related things like you know buy a ticket confirm booking cancel booking we are handling it using booking service so payment related things in order to separate our concerns let's create another service called payment service this particular class is responsible to handle payment related things so booking service class single class for the same reasons we'll make this payment service class also as single turn so how do you make it single turn you'll have a you know private uh Constructor pment private payment service if I don't write this by default our Constructor is public so that's why I'm writing it as private here now let's write our synchronized get instance method that will be static now first I'll check if this instance is null or not if yes I'll go ahead and create a new object for this new object I cre using Constructor and then finally I'll be returning instance if instance is already created e check fail it will directly return the existing instance right so what else what is payment service responsible for payment service is responsible for processing the payments right so let's write a method called process payment and obviously this will return an object of type payment input in and obviously we'll pass payment method this payment method will come from the user check that will come [Music] here credit card string credit card payment method but how will that be converted into this uh object of type payment method we can do that using Factory design pattern we'll come to that later first now consider uh payment service is only concerned with an object of payment method and using this we'll have to um what do you call Process our payments let's just simply again create a payment new [Music] payment and then payment meth we are still here yet to use the strategy classes here but forget about the strategy classes for a moment process these payments we'll just create an object of payment uh using given amount and payment method right so we'll have to set the status in every payment strategy we doing two steps creating an object of type payment and setting the payment status but the only change here is in the payment service I want to check if it is successful then I want to mark it successful else I want to Market as failed so let me write another method called mock payment processor let's make it private because only this class is using it this will return return either true or false you can you know use this method or use this approach in your machine coding rounds just to mock uh the uh operations of third party uh apas that that you're using so even this will take amount and payment method same but when you're calling when you're actually calling third party APS you'll have to pass what is the amount to be processed and what is the method right so here we'll try to simulate the success 90% success 90% of the time success simul for that I'll just do math. random of a random uh number in this because I want to uh you know see this man you know have to I want to return true or false I'm just doing 10% of the times okay 10% of the time like whenever you call this random math. random it will gener generate a random number whenever it that random number is greater than 0.1 it this will return true so which means in 90% of the times we are you know returning true this will return true only 10% of the time where the math. random will generate the number less than or equal to [Music] 0.1 so we'll be returning false when math. random will generate a number which is less than or equal to 0.1 so this is just to mock your third party apis phone pay you'll be talking to phone p apis credit card Cas you'll be talking to credit card apis right so here let me just call that so Boolean success is equals to processor process okay here I'll just pass these two so if if it is Success then only I'll set the payment status as uh you know successful else I'll just do payment. [Music] F what is the error here a I didn't return this payment let me just return payment so mock payment you can apply to this strategy pattern that you know where we used our payment here simple I'm just creating an object and depending on the success or failure I'll set my status as success or failure I hope this is clear right now let's come to uh little uh you know how do we handle this factory factory classes and all right we'll have to see pay but someone has to call it payment service while you're booking a ticket so let's go to booking service in let me check for booking booking yeah book ticket right so first I'll check if the seats are available or not if yes I want to Mark the seats uh you know Mark the seats as booked then I'm calculating the total price a total price low I have already included the dynamic pricing aspect of my shows here what I'll do is so what I'll do payment service this is an object of the payment service class me go [Music] up and write it here private payment service payment service so using that I'll do process payment amount process Dynamic pring so total price comma what is the payment method us so even this booking service will be called from this booking service demo booking service demo it's a simulation of the user Behavior right so so let me just pass it here payment method payment method so once this is [Music] done I can do booking payment consider this is successful or failure whatever it is success faure I'll be calling my third party you know apis and depending on the result I will be setting my payment status payment stat but how do we really this payment is related to this booking for that reason we need an attribute here called private payment payment set method once the payment is done this payment service will return me an object of type payment e payment booking dot set payment of payment this is how I'm joining or I'm associating this payment for this particular booking so Logics associating Logics if you forget them in your design interview or machine machine cing interview that will create problems later links it'll be problematic again you'll have to go back and debug it will waste some time so be mindful of these uh connections most of the time we create different objects and we forget to link them like uh um in in our first live also I created multi Multiplex object but I forgot to do the step screen I didn't associate both of them together so let's not miss know make sure you don't miss [Music] them so is asking total payment objetive payment ID booking object I talking about this set payment yeah booking yeah if you want to just give it it is always good to have your object right we booking low if you see this here M up instead of you know giving this directly give private uh maybe string p payment ID right so whenever if I give this like this and I set this payment ID and whenever I want to get the payment details a particular payment booking L amount process and a user a [Music] meth again I have to do payment get of this payment ID payment ID us I have to retrieve the whole payment information simple it's not it's nothing wrong whatever you suggested you can do that but this is a better design to have your complete object to access I hope I answered your question correct payment ID just payment ID CH but when you're trying to access uh your payment information you'll have to do an other extra step on there so where will we uh booking IP in yeah so we have Associated a payment to a booking right now things are fine now let's go a step ahead and let's try to have a factory class because we'll be having credit card payment andp pment but there will be many wall you have a lot of payments here I can just add wallet payment also can wallet payment add this coach so there'll be many so the best thing to do is in order to manage all the objects for all the strategy concrete strategy classes let's create another class called payment strategy Factory so interviewer discussion what you have to understand what your interview interviewer is interested in you can make these improvements starting only one Implement CH given a limited time you implement your base code the am uh Improvement you'll have to discuss with your interviewer and once you agree on some requirements you'll have to uh you know create these classes and Implement those things so you can just before creating a factory you can mention [Music] that so just to make it extensible I can create a factory class where I you know handle you know hand over the creation of uh these conrete strategy classes to another class called Factor class so this is uh this shows that you're following solid principles so I strategy Strat just go here and delete it new payment strategy [Music] Factor so in the law uh generally uh payment uh the creation of objects is given to a static method so that you need not create another object for this uh Factory simp if I have a method called get payment strategy Factory class in order to create objects which are related to payment strategy different payment strategy objects and the name is get payment strategy so this will return what this will return a payment strategy so then will pass payment method so depending on my payment method input I'll be creating objects for that particular credit card credit card payment object return so just use a switch for it payment [Music] method case credit [Music] card so if it's credit card I'll return credit card payment if credit card payment is implementing payment strategy and the I'm returning payment strategy here okay [Music] because we have only two strategies here I'm only writing two cases card payment add those conditions here default you can write cred card and payp if you have another input we'll be throwing an exception illegal argument exception message invalid payment method so now once we have this now this particular method get payment strategy is not static generally the good practi is I'll write static here strategy again obviously I can create multiple objects for this class and each object will be calling get payment strategy you can make it a unified method from which you can fact be creating different products payment be getting different objects so that's the reason we write static there so now we have we'll have to use it obv payment service K we'll be using it here payment meth right so payment method I'm doing this you know payment and then setting the payment payment process we'll have to use the strategy classes here right so instead of using this payment passing this payment method if we pass the payment strategy we can make use of this uh where are they we can make use of these uh concrete classes [Music] if you see this credit card payment no usages even in this pay payment no uses payment service law I'm I want you know I'm directing my payment object uh to process the payment this is a new implementation that have written so e implementation is getting duplicated here and we are doing the same here payment object pment stat this is what we have to avoid here we'll have to use these strategy concrete strategy classes based on the payment strategy that we get so what what can we do here I'm expecting some comments or answers from you or else let's go to booking service user payment [Music] method so payment method Factory design Factory class is expecting a payment method right so why don't I create object of these strategy classes using this method and payment method so let's go to booking service pment I'm directly calling this payment service process payment instead of doing this can we do something different Factor class because this get payment strategy is a static class I can directly access it using a class [Music] name now what what are the parameters that this is expecting simple payment method what will this return this will return as simple payment strategy so depending on the payment method that the user is selecting I'm creating a payment strategy using my factory class payment strategy now what will I do instead of directly passing this total price and uh payment method e payment service should be using my all my strategy classes correct so what should I do here no one factoring booking service payment service apart from this I'll have a private payment strategy because goal duplicate repl right replace AC using this object I want to directly call Process payment payment strategy do process payment dynamically which whatever you know the user is trying to user credit card this payment strategy will be credit card payment process payment and this will get executed so I'm just replacing this whole thing dynamically based on the payment method that is selected C single so input amount so just pass an amount here got it even this is returning payment right so now I don't need this anymore payment method payment service class that is handled that is abstracted in the booking service or booking service demo [Music] class any questions what is this uh payment payment mode was bro but amount yeah yeah I'm passing the amount here while processing the payment I'm passing the am [Music] here and that depending on that strategy strategy the way they process the payment will be different so whatever amount I'm sending that will be processed depending on the strategy that is selected by the user but problem payment strategy is not initialized yet Factory let me just write a simple method here uh and then I'll payment strategy object I'm using that here but that is not set anywhere two ways like we discussed yesterday one is Constructor and the other is Setter method either Constructor pass G or I can simply have public uh void set payment strategy and using this I can simply write this. payment strategy equal to payment strategy payment strategy so this is just one way to set the payment strategy Constructor but this is more flexible I suggest you to use this Setter method always over Constructor because this is this way is little rigid so now I'll go to my booking service [Music] so I'll just [Music] do payment service dot set payment strategy of payment strategy now once this is done depending on what the payment method user is Select payment strategy de in this line line number 6 [Music] 66 now this will do whatever we we have done here right payment service. process payment we'll again do it I'll just uncomment this KN this because we introduced we abstracted out the dependency of payment method inside this payment strategy using Factory class we don't need this anymore I'll try to repeat this from the beginning in case if you have any doubts let me know in the comment section Okay so [Music] payment strategy Factory methods comess pay sucess ofure me depending on the success value I'm setting the payment status but this is only one way to do it [Music] right now irrespective of you are selecting UPI credit card or net banking or PayPal you are executing same lines of code which is wrong even irr of what I'm selecting if I'm executing the same thing what what is the use of these different strategies like credit card but finally when you execute or check out fin even if you selected credit card but still in the back end if it is going from your UPA bank account what is the use of giving those options so and this should be removed and the payment method we have to abstract it out from our payment service payment service is only concentrate should only concate on the processing payment it should not depending on depend on this payment method go to booking service payment strategy I'm abstracting it out from our payment service payment service it will just call using the strategy I'll execute your method so that's why using a factory class depending on my payment method that the user is selecting first pay service when I do payment service. process payment in my booking service that will be calling this process payment I don't have the same implementation for different strategies or different options different options different Logics relp Rel right so I hope you understood how do we incorporate using strategy design pattern when we have different options [Music] strategy you will have to decide which strategy that you want to go ahead with we are creating a factory class Factory class I'll create a strategy and strategy strategy Serv I'll carry out my operations based on that strategy so simple right I hope you have no no more questions if you still have doubts uh you can let me know later I'll do another live or or offline video to uh you know demonstrate this if you have still if you still have doubts already R explain I think things should be good now right so this is about you know integrating payments with your booking um book bookm app and also how do you do Dynamic pricing so this is the you know from my interview experiences I have given a lot of interviews 45 minutes or 1 hour uh low level design interview so this whatever we discussed is telling you how do you just theoretical knowledge design pattern how are you implementing it how are you implementing multiple design patterns design pattern us you can't your application cannot survive generally uh you know strategy pattern to You'll also have fact you'll have you'll also have to use Factory design pattern so uh you'll have to use multiple design patterns to make your uh you know application readable and more modular payment strategy and payment service low same method name confus process payment okay let me just clarify this so yeah I understand process payment process payment there's no compulsion you can change it like um let me just change it to process service payment and go back and write s e method service class Lo payment you can change it not a big deal okay so yeah so this is uh pretty much about uh building uh bookm show this is the Max uh depth that anyone can go there there's another one also that okay let's so that you you'll be completely you know safe and you'll be aware of what what is coming from your interviewer there's one last thing okay before we end this now you have done the payment Dynamic pring [Music] imp so take a minute and think pay book my application should be responsible to notify me that your booking is confirmed and this is your ticket so how would you do that if you remember our low level design uh playlist we discuss something about Observer pattern this will using this Observer pattern we can notify uh our users after the payment is successful or failure so this can be used to notify different parts of the system system like sending an email or sending an SMS when the payment is successful or fails so if you still have time left in your interview interviewer may ask how how would you implement that so uh you can for this purposes to notifying your customers or uh you know or notifying anything for that matter customers if you want to notify a different part of your system micros Services architecture L you'll be having multiple services so multiple Services mod communication key you might have to notify some service about an event so in our case if you go to booking [Music] service successful payment or failure this can be success or failure because if you go to this process service depending on our you know mock payment process it can be either you know me uh when you actually talk to your API uh third party API it can be success or failure but still we're going ahead and creating a booking if the payment is failed the booking is failed if the payment is successful booking is successful and we'll return a ticket right so if you want to notify someone after this payment is [Music] done you'll be using Observer pattern so what are the steps to you know uh implement this take a minute and think now I'm booking a ticket where should I do it after getting my payment status I have to notify so notify correct payment service class once I every time I process a payment it's my responsibility to notify my users right separate me because notify method is being called in this method in in this class itself I'm making it private okay private void notify users you'll notify about what obviously about the payment payment success and the fail and the I'll do my you know just notification related logic because this needs a payment let me create a payment payment here payment object here and finally return payment and then I'll call this payment here so after the payment is processed irres of it is successful or failure I'll have to notify my user so payment service after processing the payment I'm writing this notify pay notify users but this is the structure so now how will you notify your users consider payment success IET I want to send this ticket to all the four people with whom I'm going to the [Music] movie yeah so Sai is asking but it violates single responsibility yeah so one thing about you know all the design principles uh you know all the solid design principles is you have to you you will have to try to implement it but you should not stretch too much it's not always possible to 100% implement or you know follow these solid design principles so process process we have to notify our user so if you want to follow single responsibility responsibility principle what will you do you'll create a separate class separate class in order to notify our users right that that's another design that's a different design that's it instead of writing a simple method here I'll move this method into a separate class and I'll be [Music] passing that classes maybe notify users and then I'll call notify user. notify users this is how you can do it right but here because just I'm just notifying users that's only single thing that extra thing that I want to do I don't want to create a separate class if so if it just one one additional thing you can add it as a method if it is if your class is getting bloated too many responsibility if it is having too many responsibilities you will try to segregate it that is the basic idea I hope that answers your question right so just to make our design simple I'm writing this notify users method here okay now let's concentrate on the original question how do you notify users using obviously in order to notify we know that we'll have to use Observer design pattern so Observer design pattern there will be some people who I registered will be listening to this payment payment success email you knows so we will have to create an interface called payment Observer so let's create another payment LW let's create another interface called payment Observer the payment Observer what will be the simp simple method notify or maybe uh update update the user that your payment is successful or failed okay so what are different kinds of uh you know Observers [Music] I'll have to write separate concrete classes so let me just write email notification Observer notification Observer and this will Implement my payment [Music] Observer let me just implement the method same again I'll create another class SMS [Music] notification obser this will also Implement payment Observer right now it's our turn to implement these you know updates so payment payment object input parameter I want to check if my payment is successful or not first right so payment dot get payment status if it is equal to payment status um let's check for successful if it is successful I'll just notify I'll just you know you know SMS uh Services key will again rely on some third party uh you know apis have third we'll be using Gmail APS so we'll be calling those third party APS for now let me just write let me just print it system.out.print SMS sent for payment ID payment. getting right so similar thing will be implemented in my email notification this will be maybe here we'll have Gmail API so email sent for payment ID so and so right now these are different observers observers and who will be receiving your notification we'll go to our payment service service because service should know who are The Observers for a particular payment then only it will notify those observers once the payment is done I'll have a list of payment Observer observers list equal to initial let's make it new list empty [Music] observers set JM add right because there will be more than one payment observers okay this is all all these things are discussed in our first [Music] right so let me just write public void add observers payment Observer let me just pass it to my observers do add of Observer that's it so now payment services aware aware of this thing now in the notify you notify let's call it users or observers it doesn't matter so notific payment Observer observer in my observers list notification key I'll be updating that the payment is done notify what is this observers payment Observer our method is update not notified so up right yeah so this is how you implement your Observer design pattern now how do we use it in Booking uh you know booking service La booking service generally not we generally don't do you know don't add our you know uh payment observers to our payment service in the booking service but for the sake of simp Simplicity let's just do that pay service I want to add some observers here one Observers email Observer Al SMS observers you can happily you know take this and create a separate method here called public void add observers observers to payment andp you can accept payment Observer and you can do payment service. add observers of Observer if you want to abstract this out to your booking service demo and so user subscri if he subscribing to booking service dot add observers to payment if he's observing uh you know if he subscribing to email you can just pass email notification observer in the same way if he subscribing to SMS you can you know add The Observers to the payment from here only uh payment service CL observers create a p so once uh this payment service do process service payment will be executed payment process it will notify the users because our particular user Rakesh is subscribed to email and uh you know what do you call SMS he list of observers we have two observers email and SMS channels we be sending the updates right this is how you implement the Observer pattern so you have different requirements different design patterns [Music] so you just don't try to remember those uh design patterns we we'll work on or we'll practice a lot of examples we'll try to build a lot of uh applications where you know it'll be habit for us we we can easily map our requirements with the appropriate design pattern to [Music] use can more than one design patterns again we'll have to so in this case before choosing strategy before choosing between strategy design pattern and decortive design pattern we'll have to talk to the interviewer actually requirement uh at at a particular point of time fil I'll go ahead and use strategy design pattern else if our requirement is to you know recursively apply filters I'll be using decorator design pattern so depending on the requirements the usage of your design patterns will change right so again this uh all these things comes with practice uh so I hope this is the last live on bookm show uh next live we'll be picking up a new problem right [Music] I'll just wanted to finish this third live and upload the whole thing to get so you I'll add this to all the three lives description you can access it and if you can add more uh you know more features to it or different ways to uh implement the same thing feel free to do that and uh me me gith particular trying to implement it and send me your GitHub links in the comment section I'll go through each and everything and then we'll discuss it in another live if you if I find any better design from whatever I have implemented right so any questions anything or you can ask me anything that you want to know let's try to utilize another 2 minutes 2 to 3 minutes to discuss any questions that you have so coming back to our you know Series in book Implement that's our first lld design that we did going forward where problems pick up J we'll try to implement them I'm also planning to do DSL lives topic wise ands topic Ma I'll be picking up uh you know live live I'll be picking up few problems and then we'll discuss different op you know different approaches to solve it and we'll also discuss the optimized solution so this is the plan yeah if you are if you say so parking l parking lot J I'll try to put up a poll YouTube Community post I'll try to put up a poll and then anything is fine for me so try to take the membership and be a part of this live DSS lives at them L lives at them we'll be doing a lot of lives from here so I think there are no more questions yet so let me just close this live again we'll try to meet on Friday IM Mao I'll try to update you guys via a video or a shot or a YouTube Community post on when I'll be doing this uh lives Ina I think if you if we have good number of at least more than 10 people in our membership I'll try to put up polls uh for members only for now the polls will be uh directed to everybody uh all the subscribers so if you like my work please do encourage me if you have any feedback coms so that I can [Music] improve but the basic uh you know bottom line is we'll be doing a lot of lives live if we stuck up in any problem live debug J we'll try to find Solutions so you can considering me you can consider me as your coding Budd where you know we'll be sitting and coding together and find optimize Solutions and even if we hit some road block we'll try to debug it so that's the basic idea of these live classes so if you have no other questions let's try to wrap up it's been one and a half hour so bye everybody see you in next live bye-bye all

Original Description

Join this channel to get access to perks: https://www.youtube.com/channel/UCT5ZpljzkT418SKoddQRrlg/join In today's members-only live session, weโ€™ll cover: ๐Ÿ”„ Strategy Pattern for dynamic pricing ๐Ÿญ Factory Pattern for flexible payment methods ๐Ÿ‘€ Observer Pattern for real-time notifications Learn practical system design with essential patterns! ๐Ÿš€
Watch on YouTube โ†— (saves to browser)
Sign in to unlock AI tutor explanation ยท โšก30

Related Reads

๐Ÿ“ฐ
Codemia Review 2026: The All-in-One Platform for System Design, OOD, DSA & Agentic AI
Learn System Design, OOD, DSA, and Agentic AI with Codemia, a comprehensive platform for skill development
Medium ยท Programming
๐Ÿ“ฐ
Stop Saying "Just Use Redis": A Key-Value Store Cheat Sheet for System Design Interviews
Learn to design key-value stores for system design interviews, moving beyond simply using Redis
Dev.to ยท Rishabh Agarwal
๐Ÿ“ฐ
Building a High-Concurrency OSINT Engine in Rust: How I Managed 35+ Async Streams Without Exhausting Sockets
Learn how to build a high-concurrency OSINT engine in Rust, managing 35+ async streams without exhausting sockets
Dev.to ยท vysh
๐Ÿ“ฐ
Microservices
Learn to split a giant application into smaller, independent microservices for better scalability and maintainability
Dev.to ยท Gouranga Das Samrat
Up next
API vs MCP Explained in Telugu | Whatโ€™s the Difference? | Complete Beginner Guide
Withmesravani_
Watch โ†’