30. Design Word Processor using Flyweight Design Pattern | Low Level System Design FlyWeight Pattern

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 68

  • @abirpaul9027
    @abirpaul9027 Рік тому +6

    This is the best channel for Design Patterns ! No one explains like this!!

  • @TsarVladolfPutler
    @TsarVladolfPutler 10 місяців тому

    Congrats! Shreyansh just laid out the foundation for the creation of the Borg!

  • @paromitadesarkar550
    @paromitadesarkar550 Рік тому +1

    Thanks for this explanation! Crystal clear!

  • @akshaymahajan9626
    @akshaymahajan9626 10 місяців тому +2

    Very well explained!

  • @RationalBeliever92
    @RationalBeliever92 Рік тому +3

    Shrayansh bro you are awesome 😎

  • @DurgaShiva7574
    @DurgaShiva7574 Рік тому +1

    apart from my open questions same as to that of asked by Kola sphoorti, its an amazing video, and an honour for me to get education from Sheyansh.

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      I have answered to Kola question. Let me check if there is any follow up question too.
      Thank you

  • @saurabhtiwari9614
    @saurabhtiwari9614 Рік тому +1

    God of DP. hatsoff to u bhaiyaa

  • @UntamedRogueMavrick
    @UntamedRogueMavrick 8 місяців тому

    A little additional point in making the object immutable, make the variable final also 12:15.

  • @goelshubham46
    @goelshubham46 Рік тому +5

    can't we make type and body as static members and then use them instead of using cache?

  • @sudarshanbaliga8957
    @sudarshanbaliga8957 10 місяців тому +3

    How will you cache objects if we want characters with different font type. Assume there are thousands of font types . What data structure will you use for cache and what will be the key ?

  • @sahild8623
    @sahild8623 Рік тому +1

    Hello,
    Can you please change the caption of the video to reflect the correct sequence numbering for the LLD playlist.... It will be helpful for someone like me who is starting with the playlist from start.
    And keep up adding these patterns to the playlist.

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      Yes, this is the latest videos, so i keep it at top for one day and will push it down in the playlist tomm

  • @iamgauravnigam
    @iamgauravnigam 9 місяців тому +1

    Hi Sir, great video, a small doubt; while calling display function second time on same Humanoid Object, old robot object which was previously displayed on x=1,y=2, will move on new coordinates. Another robot will be created only in that case, if we create a new object. Kindly clarfiy.

  • @aashishdahiya7836
    @aashishdahiya7836 Рік тому +2

    Nice Explaination, One question - where will we store the state of object (robot) i.e x & y pos - if we have multiple robots in the game?

  • @rohitkumarratnesh4780
    @rohitkumarratnesh4780 Рік тому +3

    Hi Shreyansh,
    Awesome explanation. Can you make a video on designing a payment gateway?

  • @kolasphoorti1030
    @kolasphoorti1030 Рік тому +2

    Hi Shreyansh, 2 questions here:
    1. Do we need cache in factory class to store all objects? What if we make the flightweight classes singleton? then we can get rid of cache and logic in factory method still will create only one object of one type?
    2. In word processor example, shouldn't there be multiple concrete classes of various characters and fonts extending iletter interface? Also, the cache if we need to use it in factory class, shouldn't the key in the hashmap be combination of character and font to store different objects?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      Flightweight class can not be Singleton. Because you can create more than 1 object like we did in Robot and processor example.
      Objects with unique data.
      Why we need to create unique class for each character? A field in a class is sufficient in my opinion.
      Yes i agree with you on part that, for word processor example, in cache we can generate a key by multiple combinations.
      But since our explanation, i used only 1 font Arial font, so based on character only i implemented the cache.

    • @DurgaShiva7574
      @DurgaShiva7574 Рік тому +1

      @@ConceptandCoding amazing video.. hats off 2 u sir, but still sir, why NOT singleton?... reason being we are just updating the X and Y coordinates of a SINGLE object only (by single I mean single in terms of type, i.e HUMANOID or Dog)
      Its the leverage of display function which is allowing us to update a single object, but still the previous position of the character / sprite printed remains intact, as we might had already done something like print(character / humanoid-sprite)
      we can't create it as a singleton , is this because of the fact that there are 2 implementations (humanoid and dog)of a same Interface IRobot ??.. if that so, can we create 2 separate interfaces ?.. then in that case it wont be needing cache, as we would have 2 different singleton classes ??

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +2

      There is ane more reason that it can not be Singleton because let's take an example of Humanoid only,
      Let's say i have to create a green color robot, red color robot, now do i have to create different classes for each color of robot, no i can use the same class but update my Cache key.
      Hope that clarifies why Singleton will not work here

    • @kolasphoorti1030
      @kolasphoorti1030 Рік тому +1

      @@ConceptandCoding I am still not convinced about why we can't use singleton. Let's take the use case u mentioned(where we need different color robots):
      Case 1: If we take the color as attribute in humanoid robot class , if we use singleton we need to create 2 objects, so as in case of using cache in factory.
      Case 2: since the color is extrinsic, we can remove it as attribute and put it as parameter in display method, so in that case if we use singleton, we create only one object for humanoid and same as using caching.
      So I don't see any extra advantage of caching here.

    • @karthikmenon1608
      @karthikmenon1608 Рік тому

      @@kolasphoorti1030 don't think singleton would be efficient since if you go with that approach we would need to create 26 classes which will be a lot of duplicated code.Singleton only allows one instance of a class so we would have to create 26 classes for each character from scratch
      whereas in the example in the video they used only one class ILetter to hold 26 characters then 26 instances for each character is mapped to the Hash.

  • @harshmodi8654
    @harshmodi8654 5 місяців тому

    Hi a couple of doubts:
    1) How thread-safe is the map logic? as it is quite similar to singleton null-check logic which needs lots of handling for thread safety?
    2) why it is not advisable to make intrinsic data static so that it is shared among objects of the class?
    Thanks.

    • @ConceptandCoding
      @ConceptandCoding  5 місяців тому

      The map logic in the Flyweight pattern is not thread-safe by default and requires concurrency mechanisms like synchronized blocks or ConcurrentHashMap to ensure thread safety.
      Intrinsic data should not be static to avoid concurrent modification issues and complex lifecycle management. The Flyweight pattern aims to share immutable common state while allowing unique extrinsic state per instance.

  • @dinki706
    @dinki706 9 місяців тому +2

    How do you show all characters on screen with this structure?

  • @girirajsinghrathore1749
    @girirajsinghrathore1749 Рік тому +1

    rather than caching can we not create both as singleton

  • @parteekadlakha2038
    @parteekadlakha2038 7 місяців тому

    Could we not pass the extrinsic data along in the constructor itself? Since we are utilizing a distinct object for each HumanRobot (flyweight object), what if we incorporate the extrinsic data as an attribute in the flyweight object? We could maintain these extrinsic fields as mutable, and when displaying, instead of passing them as parameters, we could directly utilize the object variables.

  • @reallanonym2015
    @reallanonym2015 Рік тому

    when we try to create a new object for same character, the first object is returned again but with different coordinate 29:43
    But suppose we want to change the font size of first object, then we cant do that since now that same object is holding the different coordinate.
    suppose i type
    This is The Tiger
    all T have different positions and suppose different font. but our sole object for T will hold the position and font only for the last T and when we try to make some changes into the 3rd T, from UI, how will the word processor that we have designed handle this issue since it has now lost the info about previous all T

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      Hi, instrinic data is one which are common for all and do not change once set.
      If this example, i make it instrinic, means font size is same for all characters.
      But in your case, if it's changes, then we can make it extrinsic and passed in display method.

  • @shubhamtrivedi2155
    @shubhamtrivedi2155 Місяць тому

    So First of all very very tanhkyou forthis video
    I get one doubt here as you are storing this object in map
    so when you get value from the map and store in a varibale as new variable will allocate new memory isn't it take again the space of object that required (31KB in this video )
    and for every new Object it will again reallocate and memoery will increase
    So the thing will remain the same How it decreasaing the memory ?
    Please give some insights I am very confused
    Thanks

  • @mskechup
    @mskechup Рік тому

    Great explanation Shreyansh, just one small doubt. For character t, all objects are pointing to same memory in heap, so what if i want to change 't' having some row, col to some other character. I know it is final, but in real word processor, i can do that.
    In this, if it is not immutable, it will change all `t` to that character in all row and col

    • @LegitGamer2345
      @LegitGamer2345 Рік тому

      Maybe we can change the letter type to being extrinsic too along with row and column being extrinsic, lemme know if you come across a better solution

  • @tejasshaha6629
    @tejasshaha6629 Рік тому

    Very good video. Crystal clear. Just 1 question - Is factory class thread safe ? Can we use concept of singleton design pattern inside factory class to make sure one and only one object is created ?
    Thank you very much ❤

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      Factory class is thread safe.
      In this scenario of factory method it worked on member variable which is HashMap, we can use concurrent HashMap if required.

    • @tejasshaha6629
      @tejasshaha6629 Рік тому

      @@ConceptandCoding Okay, thank you sir for the explanation.

  • @prepareyourself7992
    @prepareyourself7992 Рік тому

    Hi
    why we dint make intrinsic to static so that it can be shared with all the robots?

  • @yuvhrajverma9665
    @yuvhrajverma9665 Рік тому

    Sir did I understand this pattern right plz let me know the advantage of creating method for extrinsic value is that we can reuse I ject in basis of common intrinsic value and the extrinsic value passed in method can be used for other logic.
    If we don't separate intrinsic and extrinsic value then we have to create object everytime for varying extrinsic value as thses values are intialised in constructor

  • @shrshawn
    @shrshawn 4 місяці тому

    can anyone tell how an object can be simultaneously present at multiple coordinates?

  • @smitmalkan-t9h
    @smitmalkan-t9h Рік тому

    Ouick Question : why there is a need to have two subclasses ( humanoid and robotic dog) when we have type and body attributes in the class ?

  • @goutamkundu6392
    @goutamkundu6392 9 місяців тому

    how to handle font/size change in this pattern? Basically when intrinsic data is getting changed?

    • @ConceptandCoding
      @ConceptandCoding  9 місяців тому

      In the Flyweight design pattern, intrinsic data, such as font or size, is shared among multiple objects. If the intrinsic data needs to change, you either create a new flyweight object with the updated data or update the existing flyweight object, ensuring that all dependent objects are updated accordingly.

  • @asktostranger8296
    @asktostranger8296 Рік тому

    Bahya jo lld hld ki common videos he
    Like how distributed computing works
    Vo lld wali playlist me bhi add kardo

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      i have kept HLD and LLD topics in respective playlist buddy

  • @utkarshtripathi2349
    @utkarshtripathi2349 Рік тому

    Hello Sir, I just have a small doubt in game example you gave. In the example we are getting the same object from the cache and setting the coordinates so the position of the object will change. But What if we want to have multiple robot objects on the screen? Can we create multiple robot objects with same Sprite class and type of the robot as Sprite is the class which is taking lot of memory so we cache only sprite class only. Is that a good approach? also will it still be the example of Flyweight pattern too?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      Yes Sprite is a 2D bitmap, which is used to create an object on screen.
      But yes this is just an example I think of, there can be different examples too.

  • @fa1con989
    @fa1con989 Рік тому

    Quick question is it necessary to code LLD questions in JAVA in an interview ? can we use typescript instead ?

  • @gurupreetsingh8347
    @gurupreetsingh8347 Рік тому

    Hey , if intrics data is not common but extrinsic is common than in this case can we implement flyweight pattern ? If no than why ? If yes than will the implementation be same ?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      I did not get the question, intrics data mean common data only.
      How extrinsic will be common (if it's common then it's not extrinsic)

    • @gurupreetsingh8347
      @gurupreetsingh8347 Рік тому

      @@ConceptandCoding oh got it ok, that means if we don't have intrics data than we cannot apply flyweight pattern, right?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому

      @@gurupreetsingh8347 yes

    • @gurupreetsingh8347
      @gurupreetsingh8347 Рік тому

      @@ConceptandCoding thanks buddy

  • @harshithdesai9989
    @harshithdesai9989 Рік тому

    Is this course comprehensive for an interview ?

    • @ConceptandCoding
      @ConceptandCoding  Рік тому +1

      If you understand the concept it would really help you in interview

    • @harshithdesai9989
      @harshithdesai9989 Рік тому

      @@ConceptandCoding Thank you sir. One more question. This is good for Microsoft fresher system design interview ???

  • @SantoshKumar-bu2qr
    @SantoshKumar-bu2qr 10 місяців тому

    memory is limited x10 us bro moment

  • @ritwik121
    @ritwik121 Рік тому +1

    Design a banking system which allows a user to 1. Create an account 2. Withdraw or deposit funds 3. Check account balance 4. Deactivate account. Expose REST APIs in relation to these functions. No need of using a database, perform all calculations in-memory. Time limit was 1.5 hours. In the interview / review related to this round I was asked about how will you handle concurrency issues while doing multiple transactions involving withdrawal / deposit or transferring of funds from one account to another . please add this question to your bucket. @shreyansh