10. Design Logging System | Chain of Responsibility Design Pattern | Amazon System Design interview

  Рет қаралды 77,557

Concept && Coding - by Shrayansh

Concept && Coding - by Shrayansh

Күн бұрын

Пікірлер
@rishabhshekharphukan5687
@rishabhshekharphukan5687 Жыл бұрын
This is where we actually implement a Linked List from scratch to solve a real world problem!! And this proves why understanding datastructures from scratch is important and not simply use library classes. Great video!! 💯
@сойка-и8й
@сойка-и8й Жыл бұрын
Spring Security Filter chain is the perfect example of this Design pattern in my opinion..where your authentication request goes through multiple Authentication Provider
@akshatsingh02
@akshatsingh02 Жыл бұрын
Yeah, correct and not only Security Filter chain, it can be any Filters in Servlets or Interceptors in Struts2.
@Rakeshkumar-po2yg
@Rakeshkumar-po2yg Жыл бұрын
apki understanding bahot acchi hai. mujhe kafi benifit mila
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Glad to know that
@goelshubham46
@goelshubham46 Жыл бұрын
idk but does this design pattern really helps? The problem it is trying to solve can be easily solved by data structure or even by if else conditions if levels are not too many. why i would want the flow to reach it to error via info or log when i can reach there directly? or in vending machine if i want water why do i want the flow go via pepsi or coke??
@AshishGupta-n1v
@AshishGupta-n1v 9 күн бұрын
The fundamental reason is extensibility of your code. Surely you can use some data structure or if else to achieve but that will not be scalable. If a new Class comes up then you have to change you logic flow but here you have everything in your class only nothing outside of class needs to be changed. So it follows open closed principle as well
@arunshrivastava7513
@arunshrivastava7513 Жыл бұрын
How to decide when to use if-else / switch-case and when to use chain of responsibility pattern? Like in case of logger since we already know about all the handlers and the chain order in advance why not use if-else statement for each log level
@bhaskararya9112
@bhaskararya9112 3 ай бұрын
Same question..why can't we just use simple factory pattern or something like if-else statements..i guess this is just for demonstratin of chain of resp pattern, there might be other use cases where this is useful that we have not across as of yet
@prithwishdas2359
@prithwishdas2359 Ай бұрын
Using if-else or switch statements to handle different log levels can indeed work when you know all the cases in advance. However, it has a major drawback when it comes to scalability and maintainability. Suppose in the future you need to add a new log level (e.g., ‘silly’). If you're using if-else or switch-case statements, you’ll have to modify existing code to introduce the new case. This violates the Open/Closed Principle (O in SOLID), which states that code should be open for extension but closed for modification. Every time you need a new handler, you’d risk introducing bugs in existing conditions and would increase maintenance overhead. In contrast, with the Chain of Responsibility pattern, you can simply extend the chain by creating a new handler class (e.g., SillyLogProcessor) that inherits from the base LogProcessor and attach it to the chain. This keeps your existing code intact, making the code more scalable and modular. CoR allows handlers to be flexible in sequence or functionality without needing centralized conditional logic, which is ideal for logging where requirements may evolve over time.
@mohitkumarbansal3486
@mohitkumarbansal3486 Ай бұрын
@@prithwishdas2359 factory design pattern will also violate the open closed principle, I think the best way to explain chain of responsibility principle is ATM machine, as if notes of 2000 are less then it can call to class of 500 notes and so on
@muskangupta5873
@muskangupta5873 6 күн бұрын
@@prithwishdas2359 but here he is adding static log numbers in LogProcessor so how come this doesnt break open close principle, once you add SillyLogProcessor you have to add some numbers, I feel enum works best for that case instead of adding static constant values, rest all looks good to me Let me know you views on this
@vnitish14
@vnitish14 2 жыл бұрын
highly underrated playlist for System design interview prep.
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Thanks
@theaverageladka2265
@theaverageladka2265 6 ай бұрын
Hey @shreyansh , can we also use factory pattern for logging as in the video itself the logging level can be determined using the type like info, debug or error and based on the type the implementing class can print the statement ? Just curious about the different approach in this logging specific problem. Although I understood the case where the rs 2000 were being fetched from ATM.
@YuvrajSingh-qn3xh
@YuvrajSingh-qn3xh Ай бұрын
kya admi h important video par membership laga diyaa isse acha toh baki ke youtubers h jaise striver ,chai aur code, love babbar
@pulakammalathy6968
@pulakammalathy6968 9 ай бұрын
great video. one doubt is , cant we use simple factory pattern also to solve logger question ? based on log type in request, factory will return corresponding logger class and we will call log method in that class
@SugamMaheshwari
@SugamMaheshwari 7 ай бұрын
Yeah mee too was thinking on the similar lines, that factory pattern would also be a great use-case for logger example. I think shrayansh was more focused on explaining the chain of responsibility design pattern and therefore the example. In one of my past companies a good use case of this pattern is in trading simulator setup (Obviously, Connecting the dots backwards :) 1. read_market_data -> 2. build_order_book -> 3. send_data_to_strategy.... Here the sequence of events form and share the chain of responsibility.
@maggs2960
@maggs2960 11 ай бұрын
Why do we use abstract class instead of normal class in Responsibility chain design pattern, when we don't have any abstract methods inside it?
@vishalbhardwaj8577
@vishalbhardwaj8577 Жыл бұрын
Hey just a question, why can't we have three different objects and use something like a factory pattern to dynamically select the object on basis of some string(info, debug or error) and then invoke that object's logging function. Why do we need to maintain a chain of responsibility
@rawthump
@rawthump Жыл бұрын
I was thinking this too. This pattern might be more relevant for ATM where we want to dispatch the biggest note first and then the smaller ones.... for logger I think Factory should be fine?
@akshitbansal5651
@akshitbansal5651 Жыл бұрын
@@rawthump even in ATM, the simple coin DSA question would be able to solve it.
@2006kenblock
@2006kenblock Жыл бұрын
I feelfactory pattern should be a better candidate as well for a logger.
@varunr3055
@varunr3055 11 ай бұрын
ATM is an excellent example where this pattern can be used. consider a user sends a request to withdraw 5000 with his card, the system can have different handler like Card Number checker, ATM card expiry checker, user's entered pinchecker and User's balance Checker. So all these checkers have a chain of responsibility. In case the user enters a card that is not even an ATM card then the request ends there, else the responsibility goes to next Card expiry and then pinchecker and then balance checker. In strategy or abstract factory,there is no chaining. We use one strategy or the other. Forgive the bad formatting I'm typing this on my tablet using handwriting recognition
@manishbansal3861
@manishbansal3861 8 ай бұрын
great example. Just one question, why can't we use switch case here to get exact match of that object type and call its method? if none is found, default case would return.
@zishanshaikh9375
@zishanshaikh9375 Жыл бұрын
there are folks in the comment section questioning if COR is the right pattern for logger or it can be done differently, here is my two cents on this, reason why chain of responsibility is the right pattern here: let's take example of log4j, we can enable certain log level in the system like ERROR or INFO etc, this is how the error levels are defined ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF e.g. if log level is set to warn, then only warn, error, fatal will be printed, rest all logs with other log levels will be disabled like debug, info etc will not be printed Now you can see that chain of responsibility comes in handy here, lets say I have used warn as log level in log 4j and in code i have different logs like debug, info, error etc lets take error, it will go to all handlers and check what log level is enabled e.g. it will first go to debug handler, is it enabled, no, then go to next info and next warn, okay warn is enabled but the log level to be printed is error, then it will move to next handler i.e. error okay now it matches the log level to be printed and also at the system level warn is enabled and error handler is eligible for printing this log There is a order of execution here where the request may or may not be fulfilled based on what log level is enabled and the order which the request should be served is defined by the chain of responsibility pattern i.e. ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
@SIVAKUMAR-bj2vl
@SIVAKUMAR-bj2vl 5 ай бұрын
Thanks alot
@SIVAKUMAR-bj2vl
@SIVAKUMAR-bj2vl 3 ай бұрын
// Step 1: Create an abstract handler class abstract class Logger { public static int INFO = 1; public static int DEBUG = 2; public static int ERROR = 3; protected int level; // Next element in the chain protected Logger nextLogger; public void setNextLogger(Logger nextLogger) { this.nextLogger = nextLogger; } public void logMessage(int level, String message) { if (this.level
@ddevarapaga5134
@ddevarapaga5134 Ай бұрын
Super Understood thanks
@jatinukey4062
@jatinukey4062 3 ай бұрын
Great explanation on this topic.
@jayantjain1519
@jayantjain1519 Жыл бұрын
Man , you're the best person for this content❤❤❤ . Definitely recommending this channel to many.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thank you
@rishiagrawal_mtr
@rishiagrawal_mtr 9 ай бұрын
Awesome explanation. can you help me understand why we prefer this design pattern over just simple if/else in the base class to create different logger object? to avoid unnecessary iteration over complete list
@ConceptandCoding
@ConceptandCoding 9 ай бұрын
usage of design pattern is not mandatory at all, all your classes and relationships should fulfill SOLID principles, So you can also do that with if-else till its not breaking solid principles.
@ujjwalgupta1318
@ujjwalgupta1318 9 ай бұрын
For the logger method, we could have simply used Factory design pattern to determine the correct logger as per the enum passed, why do we need a chain of responsibility pattern? In this scenario, why should an error message be even processed by InfoLogProcessor?
@sunnykumarsingh7039
@sunnykumarsingh7039 9 ай бұрын
Exactly
@BRIJKISHOREDUTTBCE
@BRIJKISHOREDUTTBCE 8 ай бұрын
Hi Shrayansh, can you give the insights about logging mechanism in distributed micro-services in HLD video?
@HimanshuKumar-xz5tk
@HimanshuKumar-xz5tk Жыл бұрын
how to decide whether to use factory or chain of responsbility principle in use cases like logger?
@kashifjamil4403
@kashifjamil4403 6 ай бұрын
first of all, doing great work. I have a suggestion that it should not be the responsibility of main method to invoke the info or debug logger rather the logProcessor should be responsible of creating the chain of log processors and main method just invoke the logger and then calls it for printing logs
@ConceptandCoding
@ConceptandCoding 6 ай бұрын
Yes, that's a good suggestion buddy. The main method should simply invoke the logger, which then processes the logs through the chain. This keeps the main method clean and focused on its primary responsibilities.
@abhishekpattnaik8531
@abhishekpattnaik8531 Жыл бұрын
Great Quality content with simple explanation. Thanks
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks 👍
@aashishgoyal1436
@aashishgoyal1436 2 жыл бұрын
Brilliant content as always Keep it up Shrayansh
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thank you
@akhilaluwala8766
@akhilaluwala8766 2 жыл бұрын
. This logger can be implemented by strategy design pattern or abstract design pattern also ri8 since based on loglevel type we are implementing respective class.. whats is the use of chain of processing in classes as we know which log level type need to be used..
@HEMANTVERMA-pv2pe
@HEMANTVERMA-pv2pe 2 жыл бұрын
I also came up with that at first. It would be nice to see the arguments to use both. @ConceptandCoding
@varunr3055
@varunr3055 11 ай бұрын
ATM is an excellent example where this pattern can be used. consider a user sends a request to withdraw 5000 with his card, the system can have different handler like Card Number checker, ATM card expiry checker, user's entered pinchecker and User's balance Checker. So all these checkers have a chain of responsibility. In case the user enters a card that is not even an ATM card then the request ends there, else the responsibility goes to next Card expiry and then pinchecker and then balance checker. In strategy or abstract factory,there is no chaining. We use one strategy or the other. Forgive the bad formatting I'm typing this on my tablet using handwriting recognition
@sumitbasu5146
@sumitbasu5146 Жыл бұрын
Very helpful video..Thank you for sharing your knowledge 👏👍
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@vyankateshkulkarni4374
@vyankateshkulkarni4374 7 ай бұрын
great explanation... thanks sir ji... though the video length is 15min only.. one might need to spend more time understanding how this chain is transferring their responsibilities to next chained object.
@harishaseri
@harishaseri 2 жыл бұрын
Hey . Like you said that vending machine can be designed by the state design pattern(in vending machine design video) and here you are saying that we can do this with chain of responsibility as well. I think ATM can also be designed by State design pattern . what do you think about it ?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
yes, pls check my ATM video
@harishaseri
@harishaseri 2 жыл бұрын
@@ConceptandCoding got it . thanks
@abdulazeez8121
@abdulazeez8121 Ай бұрын
Why does the LogProcessor class have to be abstract ? it does not have any abstract method. Am I missing something ?
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk 3 ай бұрын
Can we say that this is built upon the Decorative Design Pattern with some added complexities?
@Flower_withanshi
@Flower_withanshi 5 ай бұрын
So the object creation of log like decoration pattern?
@anshulkatare
@anshulkatare 3 ай бұрын
Why not use a factory pattern here, based on Log level, we can get the instance of the logger which implements it, and use that logger to log? Why is this approach better here and not factory?
@alekyaathaluri5123
@alekyaathaluri5123 3 ай бұрын
Hi Anshul
@anshulkatare
@anshulkatare 3 ай бұрын
@@alekyaathaluri5123 Hi
@anshulkatare
@anshulkatare 3 ай бұрын
@@alekyaathaluri5123 hi
@jayatimahajan2803
@jayatimahajan2803 2 ай бұрын
Factory is creatinal design pattern and you can create multiple objects based on type. But at client application ie logger class you will need to implement switch cases and based on that you will call the object and if new type is introduced you will need to change the client code which means it will break o in solid principle
@rheumaticharm9551
@rheumaticharm9551 5 ай бұрын
Wow so many videos are members only
@kushalsheth0212
@kushalsheth0212 3 ай бұрын
this one was epic, agar iske alawa bhi aata he to 😂
@drrrpp
@drrrpp 6 ай бұрын
can this can be used for employee detail check scenario, say aadhar,pan,bank details checking one after one ??
@adityaagrawal3201
@adityaagrawal3201 2 жыл бұрын
can logger be implemented with observer pattern as well..? Where an error been written to multiple type of file or console..?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
umm, you mean to say, console, file loggers will act as observer?
@ayavi22
@ayavi22 2 жыл бұрын
Thank you Awesome explanation :)) waiting for next one!
@ayavi22
@ayavi22 2 жыл бұрын
can you add Git link please ? if possible
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Hi Avinash, pls find the git link gitlab.com/shrayansh8/interviewcodingpractise/-/tree/main/src
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Also one gentle request, if you find video helpful pls do share it with your connections . thanks
@ayavi22
@ayavi22 2 жыл бұрын
@@ConceptandCoding Yep i have suggested your channel in my team they are finding to really helpful
@ayavi22
@ayavi22 2 жыл бұрын
Please keep posting in long run your efforts will pay off. You are making many early stage devs like me life easier
@ROHANKUMAR_
@ROHANKUMAR_ 3 ай бұрын
Sir,please some video like parking lot for everyone
@indianathena219
@indianathena219 8 ай бұрын
I was recently asked in an interview to design multi tier LRU cache where each layer will have increasing size and time of retrieval. Can this be done using chain of responsibility considering if element is found, we need to populate it backwards in all previous layers for cache to be updated?
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
Yes, you can design a multi-tier LRU cache using the Chain of Responsibility pattern, ensuring that when an element is found in a higher tier, it gets populated backward in all previous layers for cache update.
@nagaakhilbelide3569
@nagaakhilbelide3569 5 ай бұрын
Can't we use a Factory pattern for logging? So, based on the LogLevel, we can return the corresponding object.
@ConceptandCoding
@ConceptandCoding 5 ай бұрын
yes we can
@alekyaathaluri5123
@alekyaathaluri5123 3 ай бұрын
Hi Akhil
@premium3968
@premium3968 Жыл бұрын
This 1 was best
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@gauravbansal1894
@gauravbansal1894 Жыл бұрын
Thanks for the video. One doubt why can't we use the factory pattern here?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Factory pattern is a creational type. It's job is to create objects. But here we are not creating objects. So the nature of work or you can say intention is different Gaurav
@gauravbansal1894
@gauravbansal1894 Жыл бұрын
@@ConceptandCoding understood thanks and your videos are amazing
@geekydanish5990
@geekydanish5990 2 жыл бұрын
Awsome content keeping posting
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
thanks
@siddharth1700
@siddharth1700 Жыл бұрын
Given the number of log levels are fixed. A EnumMap with Map would have been faster and maintainable compared to chain of responsibility design pattern.
@devanshhalwai9655
@devanshhalwai9655 Жыл бұрын
Hey! for this logger implementation can we not use factory design pattern where it can provide me the instance of logger based on the requirement ?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Factory design pattern is creational design pattern, which mostly focus on creating of object. So don't this we should use it here
@LegitGamer2345
@LegitGamer2345 Жыл бұрын
@@ConceptandCoding Could you elaborate a bit on when we to use factory pattern and when to use chain of responsibility pattern? It seems like even in chain of responsibility pattern we are creating multiple objects ?
@art4eigen93
@art4eigen93 2 жыл бұрын
isn't State DP used to design Vending machines?
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
Right but there is no one solution Aritra.
@nitigya
@nitigya 2 жыл бұрын
Why are we not using the factory design pattern?
@mohdnomaankhan2435
@mohdnomaankhan2435 Жыл бұрын
+1
@ashishgulati9539
@ashishgulati9539 Жыл бұрын
+1
@sharathkumarhk4260
@sharathkumarhk4260 3 күн бұрын
Newbie here, but I will share my opinion.. Factory patterns are essential to create objects of one type.. we can use factory patterns to decide, if you want to log into the console, file or any other modes, and it will continue to log in those created handlers.. But the logging level is dynamic and not restricted to one log level throughout application life cycle. Also, initially I was not happy with this approach, I was thinking why can't we just do it if else and check if it needs to be logged or not.. But this chain of responsibility is pretty much useful when we have multiple handlers like Console, File e.t.c To avoid code repeatition of if else in all these handlers. My final approach is, Use Factory + Singleton to create a logging handler to decide where you want to log (file, console) and then these concrete handlers will have a log function with a chain of responsibility implemented.
@dhruvsinghal6451
@dhruvsinghal6451 5 ай бұрын
Can you please explain here how parent Logprocessor is calling child log method
@alekyaathaluri5123
@alekyaathaluri5123 3 ай бұрын
Hey Dhruv
@anunaykumar2871
@anunaykumar2871 Жыл бұрын
in the main class we have made an nested initialization to the Logger class.But in actual production code there is no such nested initialization in Log4j sdk .How does that works internally then?
@shubhshah4192
@shubhshah4192 Жыл бұрын
Most probably there is a wrapper class which returns the chained object
@sombuddhachakravarty4142
@sombuddhachakravarty4142 Жыл бұрын
For this kind of design, why can't we use Factory pattern? Factory can return the required kind of class based on log level, and then use that to print the log in proper format.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
This kind of design is used when you don't know which class can fulfill the request, so it goes in chain and which ever say yes i can fulfill, it will handle the request, in that case factory pattern will not fit
@sombuddhachakravarty4142
@sombuddhachakravarty4142 Жыл бұрын
@@ConceptandCoding For ATM I agree that the COR pattern makes sense. For the logger use case we can only have a fixed number of levels that are there as an ENUM. So we can switch over the passed ENUM value to get the correct object. We can use a singleton factory to not generate new objects everytime
@ranjanAbhi007
@ranjanAbhi007 Күн бұрын
Shreyansh, Isn’t simillar to decorator design pattern.
@hrithikbabbar5721
@hrithikbabbar5721 Жыл бұрын
Loggers also come in singleton???
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Yes
@volamjeevankumar1502
@volamjeevankumar1502 Жыл бұрын
Whats the benefit of writing log processor class as abstract
@ConceptandCoding
@ConceptandCoding Жыл бұрын
I want to create child classes, you can try creating Interface too.
@abhijeetbasfore6816
@abhijeetbasfore6816 Жыл бұрын
Great
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@tansenmusician9494
@tansenmusician9494 7 ай бұрын
Isn't this design bad. Suppose in future we create a new handler and they fail to implement next logic properly then the whole system goes for a toss.
@codinggist7761
@codinggist7761 Жыл бұрын
First of all great content. I love watching your playlist. 1 question, why not enums & static vars?
@AI_for_funn
@AI_for_funn Жыл бұрын
awsomne
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@sushilverma6192
@sushilverma6192 2 жыл бұрын
For a logger implementation, what is the actual difference between COR pattern and decorator pattern?
@rajdeepchauhan5251
@rajdeepchauhan5251 2 жыл бұрын
According to my understanding, in CoR every object has its own implementation and handling logic but in case of decorator pattern, we work on the same object and define different decorators to decorate the object. We can not break the flow in case of decorators as well. [ Taken from refactoringguru ] Chain of Responsibility and Decorator have very similar class structures. Both patterns rely on recursive composition to pass the execution through a series of objects. However, there are several crucial differences. The CoR handlers can execute arbitrary operations independently of each other. They can also stop passing the request further at any point. On the other hand, various Decorators can extend the object’s behavior while keeping it consistent with the base interface. In addition, decorators aren’t allowed to break the flow of the request.
@akshitbansal5651
@akshitbansal5651 Жыл бұрын
why can't we have different methods like logE, logI, logW?
@trident8638
@trident8638 Жыл бұрын
Ideally one class should have only one responsibility as per SOLID principle. Think of error reporting class, currently it is logging an error on console but in future we might wanna send some alarms to dev teams related to error count, we can build dashboard for service health. If we have all logging method in one class then in future that class will be too cluttered
@pawnyogi
@pawnyogi Жыл бұрын
How to access car rental and car parking lot video ?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Those are accessed to members buddy. You will see join button at home page, there you can select "Unlock LLD" option.
@theritesh973
@theritesh973 5 ай бұрын
❤❤❤
@AI_for_funn
@AI_for_funn Жыл бұрын
binge watching to save myself from getting new membership next month . xD , but coding is taking time .
@ConceptandCoding
@ConceptandCoding Жыл бұрын
:) happy learning buddy but do practice with hands.
@AI_for_funn
@AI_for_funn Жыл бұрын
@@ConceptandCoding Thanks for keeping it at such low cost , means a lot for guys like me.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
@@AI_for_funn :) even though it's low but it will make you think twice before you even think to purchase course for 5k or 10k rs.
@QuickFoodGo
@QuickFoodGo Жыл бұрын
Where is the repo link? Pz send me here.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
gitlab.com/shrayansh8/interviewcodingpractise/-/tree/main/src/LowLevelDesign
@shasha6538
@shasha6538 Жыл бұрын
iska gitlab link nhi hai kya?
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Check here pls gitlab.com/shrayansh8/interviewcodingpractise/-/tree/main/src/LowLevelDesign
@homestaysandcafes
@homestaysandcafes 2 жыл бұрын
Sir code not working for me it is going in infinite loop😢
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
strange it worked for me, Can you pls debug whats the issue.
@homestaysandcafes
@homestaysandcafes 2 жыл бұрын
Debugged my issue sir, actually instead of if condition i was using while thats why it was going in infinite loop 😂😂😂
@ConceptandCoding
@ConceptandCoding 2 жыл бұрын
:) good 👍
@okeyD90232
@okeyD90232 Жыл бұрын
This could be simplified by using abstract method template with above implementation, so that you only care about how to log not when to log. The code would look like Your abstract Processor class would look like this: constructor(nextLogger) { .... } protected Logger nextLogger = null; public final void log(int logLevel, String message){.
@ConceptandCoding
@ConceptandCoding Жыл бұрын
Thanks
@vishnuvadhandevandla4110
@vishnuvadhandevandla4110 Жыл бұрын
pls do english version
@ConceptandCoding
@ConceptandCoding Жыл бұрын
All latest videos are in English only, few were in hindi. Will try to cover it in English, in Live LLD playlist (as I have covered few hindi topics in English in that playlist)
@TimeFun12
@TimeFun12 4 ай бұрын
Free me kyun de raha. Kuch video chalta hai fir paisa mangta hai
@Puklit0000
@Puklit0000 3 ай бұрын
maja nahi aaya
@sushil1922
@sushil1922 Жыл бұрын
Kindly allow access to all videos @ConceptAndCoding
@yatri6329
@yatri6329 8 ай бұрын
But ATM/Vending machine to State design ka use krte h na??
@ConceptandCoding
@ConceptandCoding 8 ай бұрын
same question can be solved using different design patterns and different ways. So there is no 1 solution
@manishsakariya4595
@manishsakariya4595 10 ай бұрын
May be more simple implementation package LLDQuestions.Logger.LoggerBasic; import java.io.IOException; import java.io.PrintWriter; enum LogLevel { INFO, WARNING, ERROR } interface LogSink { void log(String message); } class ConsoleSink implements LogSink { @Override public void log(String message) { System.out.println(message); } } class FileSink implements LogSink { private String filename; public FileSink(String filename) { this.filename = filename; } @Override public void log(String message) { try (PrintWriter writer = new PrintWriter(filename)) { writer.println(message); } catch (IOException e) { e.printStackTrace(); } } } class Logger { private LogLevel logLevel; private LogSink logSink; public Logger(LogLevel logLevel, LogSink logSink) { this.logLevel = logLevel; this.logSink = logSink; } public void log(LogLevel level, String message) { if (level.ordinal() >= logLevel.ordinal()) { String logMessage = "[" + level + "] " + message; logSink.log(logMessage); } } } public class Solution { public static void main(String[] args) { LogSink consoleSink = new ConsoleSink(); LogSink fileSink = new FileSink("log.txt"); Logger consoleLogger = new Logger(LogLevel.INFO, consoleSink); Logger fileLogger = new Logger(LogLevel.WARNING, fileSink); consoleLogger.log(LogLevel.INFO, "This is an info message"); consoleLogger.log(LogLevel.WARNING, "This is a warning message"); fileLogger.log(LogLevel.ERROR, "This is an error message"); } }
@omkaranabathula1979
@omkaranabathula1979 25 күн бұрын
Shouldn;t use ENUMS because it breaks Open/Closed Principle
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
12. Hashmap Internal Implementation in java  | Hashmap in java | Implementing your HashMap in Java
30:09
19. Design File System using Composite Design Pattern | Low Level Design Interview Question | LLD
21:30
36. Visitor Design Pattern | Double Dispatch | Low Level Design
33:17
Concept && Coding - by Shrayansh
Рет қаралды 13 М.
Design Google Calendar! System Design Series: Episode 1
36:52
Sreenidhi Sreesha
Рет қаралды 6 М.
3. Observer Design Pattern Explanation, Walmart Design Interview Question, 2022 | LLD System Design
34:34