Тёмный

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

Concept && Coding - by Shrayansh
Подписаться 110 тыс.
Просмотров 14 тыс.
50% 1

Design Text Editor or Design Word Processor or Design game
All these questions can be solve using this structural design pattern i.e Flyweight pattern.
➡️ Gitlab link:
Shared in the Member Community Post (If you are Member of this channel, then pls check the Member community post, i have shared the Git link there)
➡️ Join this channel to get access to member only perks:
/ @conceptandcoding
Chapters:
00:00 - Introduction
00:44 - Definition
01:34 - Issue in a ROBOTIC GAME Example
06:56 - How to Identify that this pattern has to be applied
11:04 - Flyweight Implementation for ROBOTIC GAME Example
21:46 - Issue in WORD PROCESSOR Example
24:46 - Flyweight Implementation for WORD PROCESSOR Example
#systemdesign #lld #designpatterns #softwareengineer #developer

Опубликовано:

 

8 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@abirpaul9027
@abirpaul9027 11 месяцев назад
This is the best channel for Design Patterns ! No one explains like this!!
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
thanks for the feedback
@paromitadesarkar550
@paromitadesarkar550 11 месяцев назад
Thanks for this explanation! Crystal clear!
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
Thank you
@TsarVladolfPutler
@TsarVladolfPutler 4 месяца назад
Congrats! Shreyansh just laid out the foundation for the creation of the Borg!
@DurgaShiva7574
@DurgaShiva7574 Год назад
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 Год назад
I have answered to Kola question. Let me check if there is any follow up question too. Thank you
@saurabhtiwari9614
@saurabhtiwari9614 Год назад
God of DP. hatsoff to u bhaiyaa
@ConceptandCoding
@ConceptandCoding Год назад
Thank you
@akshaymahajan9626
@akshaymahajan9626 5 месяцев назад
Very well explained!
@ConceptandCoding
@ConceptandCoding 5 месяцев назад
tha
@RationalBeliever92
@RationalBeliever92 Год назад
Shrayansh bro you are awesome 😎
@ConceptandCoding
@ConceptandCoding Год назад
Thank you
@UntamedRogueMavrick
@UntamedRogueMavrick 3 месяца назад
A little additional point in making the object immutable, make the variable final also 12:15.
@goelshubham46
@goelshubham46 7 месяцев назад
can't we make type and body as static members and then use them instead of using cache?
@sudarshanbaliga8957
@sudarshanbaliga8957 4 месяца назад
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 ?
@shreyshreyansh
@shreyshreyansh 2 месяца назад
character+type+size as key?
@prepareyourself7992
@prepareyourself7992 11 месяцев назад
Hi why we dint make intrinsic to static so that it can be shared with all the robots?
@girirajsinghrathore1749
@girirajsinghrathore1749 7 месяцев назад
rather than caching can we not create both as singleton
@iamgauravnigam
@iamgauravnigam 3 месяца назад
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.
@sahild8623
@sahild8623 Год назад
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
@rohitkumarratnesh4780
@rohitkumarratnesh4780 Год назад
Hi Shreyansh, Awesome explanation. Can you make a video on designing a payment gateway?
@ConceptandCoding
@ConceptandCoding Год назад
Noted
@dinki706
@dinki706 4 месяца назад
How do you show all characters on screen with this structure?
@mskechup
@mskechup 11 месяцев назад
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 8 месяцев назад
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
@parteekadlakha2038
@parteekadlakha2038 2 месяца назад
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.
@aashishdahiya7836
@aashishdahiya7836 Год назад
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?
@bikrantjajware6062
@bikrantjajware6062 Год назад
in the cache right
@kolasphoorti1030
@kolasphoorti1030 Год назад
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 Год назад
@@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 Год назад
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 Год назад
@@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.
@user-oy9xt9ez6n
@user-oy9xt9ez6n 9 месяцев назад
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 ?
@harshmodi8654
@harshmodi8654 8 дней назад
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 8 дней назад
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.
@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 Год назад
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.
@utkarshtripathi2349
@utkarshtripathi2349 10 месяцев назад
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 10 месяцев назад
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.
@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 Год назад
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.
@fa1con989
@fa1con989 Год назад
Quick question is it necessary to code LLD questions in JAVA in an interview ? can we use typescript instead ?
@ConceptandCoding
@ConceptandCoding Год назад
Any OOPs language can be used
@yuvhrajverma9665
@yuvhrajverma9665 8 месяцев назад
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
@yuvhrajverma9665
@yuvhrajverma9665 8 месяцев назад
Sir waiting for ur reply 😊
@goutamkundu6392
@goutamkundu6392 3 месяца назад
how to handle font/size change in this pattern? Basically when intrinsic data is getting changed?
@ConceptandCoding
@ConceptandCoding 3 месяца назад
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.
@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
@asktostranger8296
@asktostranger8296 11 месяцев назад
Bahya jo lld hld ki common videos he Like how distributed computing works Vo lld wali playlist me bhi add kardo
@ConceptandCoding
@ConceptandCoding 11 месяцев назад
i have kept HLD and LLD topics in respective playlist buddy
@harshithdesai9989
@harshithdesai9989 Год назад
Is this course comprehensive for an interview ?
@ConceptandCoding
@ConceptandCoding Год назад
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 4 месяца назад
memory is limited x10 us bro moment
@ritwik121
@ritwik121 Год назад
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
@ConceptandCoding
@ConceptandCoding Год назад
Thanks buddy. I am adding it
Далее
Yeni Özbək Mahnisi Yoxsa Vefali Reqsi? 😍
00:36
Просмотров 2,9 млн
5 Design Patterns That Are ACTUALLY Used By Developers
9:27
How I Mastered System Design Interviews
10:22
Просмотров 111 тыс.
How I Mastered Low Level Design Interviews
8:41
Просмотров 46 тыс.