Low Level Design 104 | How to build Classes in Object Oriented Design | 2022 | System Design

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 81

  • @tushar54983
    @tushar54983 2 ปีที่แล้ว +42

    I think it is obvious that Lesson class should have responsibility of calculating discount. Seeing other comments, sure if there is a discount on total amount, then that one will fall under Cart's responsibility. But to calculate individual lesson's discount, if we think that Cart should have that responsibility, that would mean Cart would have to create something like getLessonDiscount(lesson) and things would get weird in getTotalAmount(). Instead, Lesson should have getDiscount() and then there can be a getPrice() function in Lesson that returns getFees()-getDiscount() and Cart's getTotalAmount() can iterate through each lesson in cart and call its getPrice() function to calculate total amount, not caring about how it works internally.

    • @yauriattamimi4435
      @yauriattamimi4435 ปีที่แล้ว +2

      Agreed. This is where i think GRASP (General Responsibility Assignment Software Patterns/Principles) comes in handy. There's one principle in GRASP called "Information Expert" that's suitable for this particular case.

    • @CodeTillEternity
      @CodeTillEternity ปีที่แล้ว +6

      i think there can be two types of discount , one on individual item or one on total item which can be seasonal or weekly sale for total amount , its possible we would also need a date or day for that so also in slot class .

    • @ayushmandhar9215
      @ayushmandhar9215 ปีที่แล้ว

      @@CodeTillEternity i think the same ,thats how myntra , swiggy and other platforms work

  • @sarthakgiri4596
    @sarthakgiri4596 ปีที่แล้ว +2

    first video where I got clear distinction between composition and aggregation with example. Thank you so much.

  • @vasujhawar.6987
    @vasujhawar.6987 ปีที่แล้ว +1

    10 mins of video cleared out 10 hours of my time. Great work!

  • @anirbanhaldar4640
    @anirbanhaldar4640 2 ปีที่แล้ว +5

    wow! looks like best video of LLD series..keep going.. hats off!

  • @onYourLeftMate
    @onYourLeftMate 10 หลายเดือนก่อน +5

    I think there would be three cases,
    * The discount is same for all course : then we will add it CART
    * Each course will have their own discounts (If any popular course is there it would have less discount and if any new one is there, it would have more discount) : then we will add discount in LESSON
    * Combination of both
    what you think?

  • @dhrub6
    @dhrub6 2 ปีที่แล้ว +21

    I feel the lesson class will have the discount method, as each lesson might have a different discount percentage.

    • @happyverma91
      @happyverma91 2 ปีที่แล้ว +6

      Discount can happen on your amount payable so it should be in cart class
      But lesson can have seprate discount code

    • @linhvu407
      @linhvu407 2 ปีที่แล้ว +15

      @@happyverma91 the question is: which class will calculate the discount of a particular LESSON - obviously the LESSON class.
      Try to apply the knowledge you learned (abstraction & encapsulation). When I call lesson.getFees(), I dont care how it was calculated, just give me the prices so that I can sum them up. Dont tell me to get the base fee and get the discount code and apply the discount etc... it is doable, but is against abstraction and it's bad code

    • @ayush52905
      @ayush52905 ปีที่แล้ว +1

      @@linhvu407 @happyverma91 They main keyword here in the question asked is "PARTICULAR LESSON" which signifies the responsibility to be of the Lesson class. Had this been a general question of applying discount, it should belong to cart class.

  • @pushpendrakumarmishra2004
    @pushpendrakumarmishra2004 9 หลายเดือนก่อน

    I really loved this video. Plain and simple but easy to digest hard concepts. Subscribed as well :)

  • @ajaypanthagani5959
    @ajaypanthagani5959 2 ปีที่แล้ว +4

    Thank you so much. This was my last minute prep and I got placed in my dream company ❤️

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 2 ปีที่แล้ว +2

    Thanks a lot for such a great animation and explanation, it made it really to understand quite easily for the topics which seems to be hard to grasp!

  • @simply_homemaking
    @simply_homemaking 2 ปีที่แล้ว +5

    I feel that totalAmount() will calculate the sum of each lesson price after the discount if each lessons has a discount price seperately. Getdiscount() method should be implemented in cart class so that if the user has some coupons this method will be called and calculate the discount price. Lesson has should have the attributes of discount price or discounts percentage and actual price.

  • @wingineers
    @wingineers 2 ปีที่แล้ว +5

    Discounts should be calculated in the Cart Class as after adding items to the cart when the user would be purchasing the lessons the system will prompt a message of whether user wants to take discount or not. Anyways thanks for the wonderful series 🌻♥️

    • @aswinikumarsahoo6459
      @aswinikumarsahoo6459 2 ปีที่แล้ว +3

      But the question was asked to calculate the discount on particular lessons only. So, according to you, will there be any id given to each lesson, according to that id the getTotalAmount() in the Cart class will calculate the total amount with discount?

  • @EFFICIENTCORPORATES
    @EFFICIENTCORPORATES 2 ปีที่แล้ว +2

    09:32 The Responsibility of calculating the discount should be with the Cart Class.
    Reasons:
    1. From a business point of view, discounts are applied when we make bulk purchases or purchase over a certain limit. Since all these calculations are there inside the cart class, so, it is wiser to keep this inside cart class only
    2. Also, Business runs combo offers, where if two particular products are purchased, the discount is applied, so, even this information is already there in the cart class, hence, the discount is better placed in the cart.
    Doing this, also hold the abstraction principle, as some other class need not know, what are items added and how the total price is calculated. The cart class can simply return the net payment amount after discount to the user, who will then check out by making payment.
    PS: Any corrections/ alternate views are welcome.

    • @sudocode
      @sudocode  2 ปีที่แล้ว +6

      It depends on use cases. There can be multiple types of discounts. Discount on item level, coupon discount, seller discount etc. only the discounts which can be applied on the whole cart irrespective of the seller or item can be kept in cart. The entity specific discounts like item or seller or coupon shall only reside with those entities. For eg: if the item search has to show discount on items, and discount is stored in cart, how would the item discount be displayed ? It won’t fall cart because cart would be empty at that time.

  • @akashjain5931
    @akashjain5931 2 ปีที่แล้ว +1

    Great Explanation! Please keep them coming!

  • @ritwik121
    @ritwik121 2 ปีที่แล้ว +1

    Thanks for making this LLD Series

  • @hastimalpaliwal483
    @hastimalpaliwal483 2 ปีที่แล้ว

    Thank you .....for sharing the LLD Knowledge.
    It's a great help.🙏

  • @prashantlalwani527
    @prashantlalwani527 ปีที่แล้ว +1

    I think discount should be in cart class as in that class we can calcute the discount of individual lesson added and and total discount can also be calculated after calculating individual discount of all lesson.

  • @abhishekgoyal274
    @abhishekgoyal274 ปีที่แล้ว +1

    I think the answer to the question depends on the type of application we are developing. If our application logic provides a discount for each lesson separately then we should implement it in lesson class as a user can be using multiple coupon codes for different lessons, and the cart has to have the member for which code which lesson gets a discount, but if we provide discount on the whole cart then it should be the responsibility of cart class to handle discount, or we can give the responsibility of specific lesson to lesson class and for the whole cart to cart class. We can also make a separate class for disscount which takes the coupon code and gives back the discounted price.
    please comment and tell me if any mistakes in my solution.

  • @natarajgn
    @natarajgn ปีที่แล้ว

    Thanks a lot sister, you are doing a great job to help us understand OOPS.

  • @parassetia1593
    @parassetia1593 2 ปีที่แล้ว

    Its quite helpful to clear the fundamentals which will impact to crack many big concepts thanks keep doing love to learn from u guys 👍👍

  • @rahulgrg71
    @rahulgrg71 2 ปีที่แล้ว +3

    Should our entity classes have methods like calculateDiscount or even makePayment() ? Because in real scenarios we generally have the service classes which implement these kinds of methods as any kind of business logic should ideally stay away from entity/beans. We just use these beans/entities to store the state. Please let me know if there is something wrong with my understanding.

    • @sudocode
      @sudocode  2 ปีที่แล้ว +2

      You are right. It depends on service complexity and the architectural practices followed.

  • @PhenomenalInitiations
    @PhenomenalInitiations 2 หลายเดือนก่อน

    Ans to her question is at 8:51

  • @kirtisingh-p4q
    @kirtisingh-p4q 10 หลายเดือนก่อน +1

    In the problem she asked the discounts can be part of lessons class also we can have some discounts on particular lessons as well as we can have cart discounts like after a certain amount a discount is applied so can we implement an interface of discounts and use them in both the classes.
    Can you please correct me if wrong?

  • @SrikanthBhospet
    @SrikanthBhospet 2 ปีที่แล้ว +1

    Amazing, Thank you for sharing the knowledge..

  • @MrRamesh940
    @MrRamesh940 2 ปีที่แล้ว

    Thank you so much for such a good explaination. great video.

  • @arjunkhanna1803
    @arjunkhanna1803 2 ปีที่แล้ว +4

    If we want to give discount on total amount then implement discount method in cart so that lessons class do not know about total amount
    And if we want to give discount based on lesson price and not on total amount then implement the discount method in lessons class and expose getPriceAfterDiscount method instead of price method to that cart class in this way cart will not know about price of lessons instead it will directly know the discounted price

    • @shashankmishra484
      @shashankmishra484 2 ปีที่แล้ว

      There may also be a case that discount on total price can be done on cart class, and the lessons eligible for discounts can be figured out by a method present in lesson class like isDiscountable()
      Ofcourse all in all, it would reside in cart class if its total based, but can have internal calls in itself as well
      @sudoCode are the above two comments good for discussion in interviews, or we can be oversharing or something like that which can give negative impact?

  • @shubhimohta8488
    @shubhimohta8488 2 ปีที่แล้ว +1

    Great videos!

  • @kunalsahu3903
    @kunalsahu3903 2 ปีที่แล้ว +1

    Thank you so much great work

  • @chinmayeejoshi2119
    @chinmayeejoshi2119 2 ปีที่แล้ว

    This is a really nice series.

  • @palaktosh2256
    @palaktosh2256 2 ปีที่แล้ว

    Wow sudocode, you explains concept so well.

  • @AshishKumar-us6jz
    @AshishKumar-us6jz 2 ปีที่แล้ว +1

    Could you please clarify why credit card and payment can't have "Has-a" relationship as aggregation? A payment can be done using credit/debit card, netbanking, upi or through cash. But a credit card will always be used to make payment.

  • @amanamudoaka8020
    @amanamudoaka8020 2 ปีที่แล้ว +1

    I love you. Perfect tuts

  • @jayendrasingh9260
    @jayendrasingh9260 2 ปีที่แล้ว

    Well thoughtful video got to learn lots of insights ... thanks mam 😊

  • @RalfGoesRandom
    @RalfGoesRandom 2 ปีที่แล้ว

    Hi, I'm a new subcriber!!
    A very impormative video. Thank you!

  • @yauriattamimi4435
    @yauriattamimi4435 ปีที่แล้ว

    I would refer to GRASP (General Responsibility Assignment Software Patterns/Principles) coined by Craig Larman that I personally think would be useful in terms of the object/class responsibilities.

  • @toptrendingworld8156
    @toptrendingworld8156 2 ปีที่แล้ว +1

    Thank you for this course. Can you please advise me on what book should I buy to learn Class Responsibility and Abstraction/Encapsulation to be able to design like you on this video?

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      There is a video on the channel where I recommended 5 books. Please check that

  • @palakjain2505
    @palakjain2505 2 ปีที่แล้ว +1

    could you take an example and explain how to design/code it up from scratch using design principles?

  • @dhananjayahm4261
    @dhananjayahm4261 2 ปีที่แล้ว +1

    Ma'am I want to become a system gesigner..so what's the 1st..step ..pls tell me and how to do prepare..my self about system designe..

  • @dhruveshkhandelwal8104
    @dhruveshkhandelwal8104 2 ปีที่แล้ว

    if discount is of a particular lesson then it should be present in lesson class and then one can have getActualPrice getSellPrice and getDiscount.

  • @rahulshukla5033
    @rahulshukla5033 2 ปีที่แล้ว

    Keep going 💫

  • @ztrixx3280
    @ztrixx3280 ปีที่แล้ว

    Lesson class should have the responsibility of calculating the discount, and the cart class should get the discounted final price.

  • @DecentProgrammer
    @DecentProgrammer ปีที่แล้ว

    Great Content as Always. Keep making such videos. Thanks for helping engineers :)

  • @souravkumar1608
    @souravkumar1608 ปีที่แล้ว

    discount should be applied here on the cart side.

  • @sarin7310
    @sarin7310 2 ปีที่แล้ว +2

    Can you please append some numbers to know the series please?

    • @sudocode
      @sudocode  2 ปีที่แล้ว +1

      Good suggestion

  • @tirupatirao7521
    @tirupatirao7521 ปีที่แล้ว

    The best of best

  • @saimanasakanduri8019
    @saimanasakanduri8019 2 ปีที่แล้ว

    Can anyone help me with understanding the credit card and payment relation.

  • @backlogbatch
    @backlogbatch 2 ปีที่แล้ว

    Thank you❤

  • @soniamalik4929
    @soniamalik4929 ปีที่แล้ว

    I think solving this amount-discount will be replicated for each lesson so it's better to do this task in cart once.

  • @Akaash449
    @Akaash449 2 ปีที่แล้ว

    Isn't credit card a type of payment?, so shouldn't it be is-a with payment ?

    • @sudocode
      @sudocode  2 ปีที่แล้ว

      Payment can be done via credit card or debit card or netbanking. So payment will have one of the ways to get payment done. Hence payments has the info of how the payment is done and that’s by credit card.

    • @Akaash449
      @Akaash449 2 ปีที่แล้ว

      @@sudocode sorry, still not clear😅. So shouldn't debit cards, credit cards and net banking be inherited from payment as different forms or types of payments ?

    • @vsinghal85
      @vsinghal85 2 ปีที่แล้ว

      As per my understanding, Payment is one of the function performed by credit card or debit card. They are not type of payment, but payment is one of the function of these classes. From customer class as part of checkout method we should do something like creditcard.makePayment

  • @chinmaysharma1867
    @chinmaysharma1867 2 ปีที่แล้ว

    Will i get job in Dubai as software engineer after completing MCA with required skillset ??
    Please reply

    • @sarin7310
      @sarin7310 2 ปีที่แล้ว

      Why only dubai?

    • @chinmaysharma1867
      @chinmaysharma1867 2 ปีที่แล้ว

      IT boom is about to come in Dubai. That's why I said.

  • @AbhishekYadav-fb3uh
    @AbhishekYadav-fb3uh 2 ปีที่แล้ว

    Great

  • @tech_wizard9315
    @tech_wizard9315 2 ปีที่แล้ว +2

    What i really love about your videos is ,they are Very simple,easy to understand and relevant! 😊 You have support! ❤️ #50k
    - Rahul Balani

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 2 ปีที่แล้ว +1

    Just had quick question regarding the relation b/w Credit card and payment. How should we implement this in our code , show we pass it as constructor of another class? Could you please suggest. Thank you!

    • @AnkitRaj-er5xl
      @AnkitRaj-er5xl 2 ปีที่แล้ว

      You can use strategy pattern to implement it.

  • @shaileshwaghmare3
    @shaileshwaghmare3 2 ปีที่แล้ว

    Pro tip: play video at 0.75x speed

  • @SHIVAMGUPTA-wb5mw
    @SHIVAMGUPTA-wb5mw ปีที่แล้ว

    your speed of talking too fast . Normal spped is looking like 1.5x. Now i am on .75x😀😀😀😀

    • @sudocode
      @sudocode  ปีที่แล้ว

      It’s my brain that thinks fast and hence the words 😎

    • @nehaagarwal3911
      @nehaagarwal3911 5 หลายเดือนก่อน

      @@sudocode And here I'm playing this video at 1.75x