System Design Full Course Visitor Design Pattern | UML + Code | System Design
Visitor Design Pattern | UML + Code | System Design Transcript and Lesson Notes
حنجی تو کرے شاٹ, Welcome Back Coder Army our Celestial D series and today we have brought a new and easy design pattern which is called Visitor Design Pattern Now what does this design pattern say? And how does it compare to other design patterns such as strategy pattern we will see in this video
Quick Summary
حنجی تو کرے شاٹ, Welcome Back Coder Army our Celestial D series and today we have brought a new and easy design pattern which is called Visitor Design Pattern Now what does this design pattern say? And how does it compare to other design patterns such as strategy pattern we will see in this video
Key Takeaways
- Review the core idea: حنجی تو کرے شاٹ, Welcome Back Coder Army our Celestial D series and today we have brought a new and easy design pattern which is called Visitor Design Pattern Now what does
- Understand how visitor fits into Visitor Design Pattern | UML + Code | System Design.
- Understand how design fits into Visitor Design Pattern | UML + Code | System Design.
- Understand how pattern fits into Visitor Design Pattern | UML + Code | System Design.
- Understand how code fits into Visitor Design Pattern | UML + Code | System Design.
Key Concepts
Full Transcript
حنجی تو کرے شاٹ, Welcome Back Coder Army our Celestial D series and today we have brought a new and easy design pattern which is called Visitor Design Pattern Now what does this design pattern say? And how does it compare to other design patterns such as strategy pattern we will see in this video today you will understand it very easily and it will be very fun so let's go to the screen See, first of all we understand that Visitor Design Pattern is called This is a very easy thing imagine that you have a class let's say A and what is in this class? You have put two methods M1 and M2 okay so everything is going well okay but tomorrow let's get a requirement in which another method is needed which is called M3 now let's say you put it in this you put M3 then another requirement which is called M4 so you put M4 Now you know what is the origin of it? as we are going to get a new requirement we are going to put this class in this method so what is this?
you know which solid principle is breaking first of all OCP Open Close Principle is breaking because we are going to add new methods in the same class which we are going to open this class again and again and modify right OCP is the same it is open for extension but close for modification but we are going to modify it again right? The other thing is that there is another principle break obviously single responsibility principle will also break because if you are going to make all these methods and you can do that there are many methods different responsibilities are handling right? means different reasons to change this class right? SRP is the same so what is happening here?
OCP is boiling SRP is boiling but what is happening here? there is another thing going on here for example your class is becoming very complex right? Complex queue if you think all these methods will be introduced so it will be difficult to test that is, you will not be able to test it tomorrow from every method right? so complex is your class so these are many problems for you if you start adding multiple operations in one class and why is this happening?
because new requirements are all so like the first MWRM2 and this new requirement is sorry this new requirement is for M3 and this new requirement is also available okay? Now to solve this problem we have a visitor design pattern this is a very simple design pattern but this is a problem which you will think that other design patterns were also doing like strategy pattern we will compare it later but now we understand what is the visitor design pattern and how this problem is solved okay? so let's take an example let's take an example of a document element okay? imagine that we have an application which has multiple documents like we handle text file okay?
we handle the image we handle the video so what is the document type? so let's do one thing first of all we make a parent class let's make a document element document element okay? so we made a parent class now if we say we handle it we call it method then we will see now we say the document element is a parent class and every document is a child class so let's have a text file so we have a child class so we have a child class so let's have a child class which is the name of the child image document okay? you can say simple image so we have a class so we have a video so basically what we are doing?
we handle the documents in one hierarchy because we know that all of our documents sorry we know that the text file, image file, video what is the problem? we have extended the document we have inherited it we have recalled the problem what is the problem? the application which is handled by the documents the requirement is going on the first requirement is you have to calculate a size of a document I will give you a method of the size of the document okay? and I will overwrite every place the text file will calculate the size of the document and then we will say we will calculate all the documents how to calculate the size of the document this is done this is a requirement then you have to calculate the size of the document and this is also a requirement that you have to compress the document so let's say compress okay?
so I have made a abstract method and I will call my own compress method and then I will call it and compress my own file okay? so what did I do? now see, we know how to compress the text file like in the JPG format in the IMGJPAC format in the IMG format how to compress the same video how to compress it all of them will use their own compression algorithms but you will know that every compress is known now you understand and the new requirements are coming now we will say compress and calculate size let's take another one let's say scan 4- now this method will be called so you can check the file there is no virus in it so you can override it scan 4- and then you can override it so you understand the same thing we saw because the new operations are coming although the document is the same as our abstract class but when it is increasing so all of this is increasing we have to write it logically because of that we talked about the principle which was open, closed, single, responsibility and we talked about that our class is getting complex so this principle is breaking now remember the basic rule of design patterns was that on the very basic level the exact word changes so the entire application which changes again and again let it out of class so that the change is not going to be the same now we take an assumption and then we start the visual design pattern and the assumption is that I am telling you that we are going to the test that our types of document are going to have a text file and we have a video I will not change this I mean we have not introduced the new types of documents we have already mentioned we have not taken a new type of document element so we have taken a PDF we are not going to do this we are just supporting these three and if we are going to do it it will be very rare we have never made a new type of documents to handle this we have made these three documents as such and I am saying that we do not want to extend this is a frequent change this is less likely frequent change every text file has a video file we will increase the operations but we will not increase the files no PDF file will not be done so if we want to make these operations and encapsulate design patterns we will introduce our visitor pattern what is visitor pattern we will do it all the methods we made here we know we are changing the class so we have done this class nothing is in this time so we have calculated the size and the scan for virus we will declare the class first we will take all the methods we have removed now why we did it now we will introduce a visitor there is nothing this is a different hierarchy we are going to do this first we will make the parent class we will use the name of the object we will use the name of the object a denotions is a class interface first we made the name of the visitor we will write the name of the object we will make an abstract and we will see what we have we have the kinds of documents we have a method basically i am using the method over loading i am using the method over loading i am making a three-visit method visit so visitor has now what are the three methods we will do in different parameters we will take a text file text file t and we will declare this we will take an image we will call it and we will take one we will call it we have done three-visit methods we have done three-visit methods we have used the method over loading and we have used the method for every document for each type we take a text file we take an image for this and we take a video for this we have made three different-visit methods this is our abstract class now what are we doing we are going to make the concrete classes now we have the methods which we have removed which were the operations which were increasing we will take the concrete classes so that if there is no new operation we can do all of them what are we saying now first of all we have the first operation we have made a visitor a size calculation visitor let's name it a size calculation visitor i will explain what i am doing so we have a visitor so let's see what we are doing i said that we have three methods we have three methods i.e. if we have to override the three methods we will override the three methods how to do the visit and how to override the three we take a text file text file t we will do something we take an image we will define the image and we take a video we will define it now see what will happen simple this is the size calculator what we have done we have done three methods to override the three methods and the text file we have written in the text file we have done a method if we have discussed the same method and the same method and the same method the three methods i have taken the text file out and put it here the calculator is there and the calculator is there so the size calculator visitor decides how to calculate the size so we have three documents so we have three methods and each method is calculated because this is the work see this this is a size calculator now we have another method you know what is the name of it the name of that method so we have not visited the new method we have called it a compress visitor let's do it compress visitor compress visitor will do the same we will override the three methods and we will have three methods visit and we will take three documents and we will have the text file and the image let's say IMG and the video and now you will understand what you are doing this is the compress visitor we will write the three compress algorithms here we have the compress we have a compress and this is the compress the same method اس کو کلاس کے اندر لکھا ہوا تو ہم نے اس کو اٹھا کر کے یہاں پیدا لدیا تو ہم یہ کر رہا ہے اب آپ کو سمجھا رہا ہوگا کی سے میں کیا فائدا میں لڑھا .
اب لیٹھ سے یہاں پیدا ہوگا ایک تو ہم ہوا ہم ہوا ہوا کیا سائیس کلکولیٹری اور ایک تو ہوا کیاکبریچان جو پہلے یہاں لکھے ہوئے تھے اور سبو سے Over-Eight کرتے تھے فینا ہمارا 30 ریکھ اور میں θلایا تھا scan for virus تو اب ہمیں دیکھو scan for virus کے لیے کسی لیے کلی جا کرکہ کچھ چینچھی کرنگا ہمی کیا کرنے ہے ایک نی سبکلاز بنانی ہے رائٹ ہمی دیکھو یہ ہمی بناتے ہیں نی سبکلاز بنانی ہے جس کا نام ہوگا لیٹسے سکن بائرس ویزیٹر لیٹسے سکن بائرس ویزیٹر اب اس کا کامہ کو سمجھائی راوگا یہ اس کے پاس بھی تین ویزیٹ میتھڈ ہوگے اب کو سمجھائی گیاتتین ویزیٹ میتھڈ یہ اپنی پیرینٹ کلس کے اور اس ویزیٹ میتھڈ کیا کریں گے وہ سارے اب اس کو میں کھالی چھوٹروں پر آپ سمجھی گیا اسکنگا کیا ہوگا تین و ویزیٹ میتھڈ اپنے دکیمینٹائپ کے سکن فروائرس والے جو میتھڈ سے اس کو یہاں پیلک دیں گے بیسکلی یہاں پیلک دیں گے بیسکلی یہاں پیلک دیں گے بیسکلی یہاں پیلک دیں گے اب اسے بے کیا فائدہ مل رہا آپ کو پتایا ہے کوئی بھی نہیں کلا ساتی ہے ہمیں کوئی اسی بھی برینسیبل بریکنگ کرنا پڑھا ہم اس کی نہیں سبتائی بنہتے اور وہاں پیپنا میتھڈ لکتے ہیں اور کوئی نے آپریشن آیا سبتائی برایا بھاں پیپے میتھڈ لکھا تو ہم یہی کر رہے جو جو ہمارے پہلے اپریشن ستے ہیں ہم نے ان آپریشن کو ایزا کلس ایس کر لیاں کیا ہمارے پاس جو بھی دکیمین ٹیکٹش فائل ایمیچ فائلی اویڈو فائل میں اپریشن سموجود تھے اُن کو بہار ایک سٹریک کیا اور اُن کو ایک فیزیٹر حیرار کی مہدہل دیا یہ نیے ہماری ویزیٹر حیرار کی ہے اور اس میں اُس کو ہم نے دیا چکے اور اب ہم نے دیکھو کیا کیا اب ہم نے دکیمینٹ لیول پے دکیمینٹ لیول پینا اب ہمارے پاس بھیل ایکی میتھڑوںہ چے وہاں سمپل ہو جائے گی اس میتھڑ کا نام ہوگا ایک سپٹ اور یہ کی ایک سپٹ کرے گا ایک ایویڈو فائل کیا لیکن سی بھی یہ بھی اس کو سپٹ دکلیا کریں گے کیا اپسٹیکٹ ہے اور یہ سب کے پاس بھی ایکی میتھڑا جائے گا ایک سپٹ ایویڈو فائل وی اور یہ سے اووورایڈ کر لے گا سیمین دونوں کے پاس آجائے گا تو دیکھو تینوں کے باس ایکی میتھڑے ایک سپٹ میتھڑے یہ ایک ایویڈرٹائی کو اوپجگ دیت لیتے ہے تو میں اس کو بولا سائیس کلکڑیٹر ویڈرکو اوپجگ لی تو جسی میں اس کو سائیس کلکڑیٹر ویڈرکو اوپجگ دیا اس کا ایک سپٹ میتھڑ کال ہو گیا اب اس کا ایک سپٹ میتھڑ اندر سے کیا کرتاوگا ایک بر ہو دیکھ لیتے اور فیر آپ کو پتا لگے گا کہ یہ اس کا خود کا ایک سپٹ میتھڑ کرتاوگے یا کسی کے بی Except میتھڑ بی تو وہ بس ایک چیس کرتاوگا وہ کرتاوگا ایک سپٹ میتھڑ وہ کے لраф ایک آئی بھی اور میں کہورم وہ بس ایک چیس کرے گا یہ جو بھی جتر εناوز کے بس اس کا بیزٹ کال کر دے گا بھی کا بیزٹ کال کر دے گا خود کا رفرèنظ 디کھے کیوں آپ کو بتا یہ جیسے یہ V کا Vz call کرے گا اس کے بس کون Sa Vz pass کیا ہم نے size calculator visitor یعنی کی اس کا Vz call ہوگا اب اس کے بس تو 3 Vz call ہوگا 3 méthod over loading uskurne 1 text file 1 image or a video اس نے reference dya kudga this یہ ہے کیا kud ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ ۔ اس میں پہلا والا வیزٹ ہے اس کو پتھیک ٹیکسٹ فیل کو کیسے کم پر ایس کرتے ہیں کیوں کہ پہلایس کا λوجک اس کے لگہ ہوا تھا میں نے اس λوجکہ ٹھا کر کے بس اس میتھر کے اندر دال دیا تا کی مجھے بس یہ کرنا پڑے جیسے کوئی ایک سیٹھ میتھر کال کریں اس کے لگہ ہوا V.Visit کیا Visit کرو this تو اب پہلای ایک تو پہلایسیٹھر پہلایسیٹھر پاس کیا وہ دیکھو main میں فیل 1.except size calculator visitor تو یہ والی class call ogue ہے نا اس کے بعد ہمارے پہلایسیٹھتے ہیں تھین Visit ہے تو کونسى Visit call نا چیسے اس نے اس میں پہلایسیٹھر V.Visit تو کونسى Visit call نا چیس نے referenzia khudka یانی کی پہلای والا Visit call ڈو اب اگر ایمیت call ڈا تو یہ بھی یہ same code لکتا V.Visit this دیکھو code یہاں پہلایسیٹھر بلکل same رہنے والا ہے یانی کی اب اس حیرار کی کونا ہمیں کبھی تچ کرنے کی ضرورتی نہیں پڑنے والی ہمیں ایشا یہ same ھی رہنے والا ہے کیونکہ سب کے accept میں بس اگی لین لکیوگی V.Visit this اس کے accept میں بھی اس کے میں بھی اس کے میں بھی کیونکہ سب کا this הلا گئے اس کا this hai text file اس کا this hai image اور اس کا this hai video تو جب یہ V.Visit this call ڈا نا size calculator visitor میں اسٹائن یہ والا اپنے آپ کی بس کیا پاس کرے گا امجھ کر رفرینس پاس کرے گا اور یہاں پہ کون image کر رفرینس لے رہے یہ بیچ وولا میں تڑ same جب یہ V.Visit call اپنے آپ نا خود کا this reference دے کے تو یہ video رفرینس لے گا اور یہ یہ last fall same ghost for compression and same ghost for scan virus visitor اس کے accept میں کو this file 1 size calculator میں نے اسٹائن میں کو this file 1.except اس بر دوبار accept call کر دوبار accept call اور اس بر پاس کر دوبار نو let's say compress compress visitor اب اپنے اسٹائن بر سمجھ گا جیسی میں نے file 1.except compress visitor call کیا تو کیا ہوا ہوگا اس text file again دوبارہ سے اس text file accept call ڈا اس میں ve.visit and this and this compression visitor یہ والا visit call ڈا اور میرا compression اور اسے scan 4 virus نو تو میں کو simple ڈا فائل 1.except اپنے آپ کو بتا یہ باس کر دوبار scan virus visitor اور جیسی ہی میں یہ کر ہوں گا آپ کو بتا ہے accept call ڈا وہ اندر سے call کر دوبارہ ve.visit this this reference یہ نی کی یہ والی اپنے آپ کو اس میں تھوڑی بہت similarity دیکھی ہوں گی stratag design pattern یہ یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ اپنے یہ جو Question آپ کے منمیworms stratag یہ اپنے یہ اپنے یہ اپنے یہ یہ وہ اس اپنے یہ یہ یہ یہ یہ یہ یہ یہ یہ یہ یہ کیاکھا ڈیجی کر رہا ہے کیا வیزٹر پہلے چلتے ہیں اس کے قوڑ کی درف تو دیکھو بلکل سیمپل وہی قوڑ ہے ہم نے سپ سے پہلے فائل سیسٹوم بیزٹر منایا ہے اس میں 3 métھر کے بیزٹ بیزٹ بیزٹ 1 ٹیکسٹ فائل لیتا ہے 1 ایمے چھپائل اور 1 ویڈیو فائل یہ نے دکھس کیا تھا اور فیرپنہ ایٹم ناتے فائل سیسٹوم ایٹم تو ہم نے بس یہاں پہل اس کے نام دیدی ہے وہ ان کنسٹر میں نام لیلیتا ہوگا اور ایک گٹنے میتھر تکلیا چھوٹا ساچی کیا اس کے لابا جونا مین میتھر تھا جو کی ورچل میتھر دین کی اپسٹرٹ ہے وہ ہے ایک سبٹ وہ ایک فائل سیسٹوم بیزٹر نام کا اپجھٹ لیتا ہے بیزٹر اور اس پے ایک سبٹ کال کرتا ہے اب یہاں تو اس کو دکلی ریشن ہے اس کو دفین کون کرے گا اپنی ٹیکسٹ فائل ایمیت فائل وہ سبٹفائیں گے گے تو یہ تو باری پیرینگلاز ہوئی فائل سیسٹوم ایٹم اب چلتے ٹیکسٹ فائل پے ٹیکسٹ فائل کیا گے گی اوگرسلی اس کے پاس اپنا خودگا ایک لیٹسے کنتنٹ ہوگا وہ کنتنٹ لیتی ہوگی گیٹ کنتنٹ میتھر ہوگا یہ سبٹو کھر بیزنال سلوجے گے مین میتھر ہوگا ایک سبٹ وہ کیا کرتا ہوگا گئییں فائل اپ ٹیکسٹ فائل کے لئے لوگ پاتھ ہے کیا سٹٹ فائل کا وہ سائس کلگلیٹ کرتے ہیں اب یہاں بھی ہمیں کوئی لوگگی نہیں لکھا کیا اگی ان وہ تو بیزنال سلوجے گے آپ کو پاتھ ہے ٹیکسٹ فائل کا سائس کسی کلگلیٹم کروازکتے ہیں ایمیتھ کا کسی کلگلیٹ کروازکتے ہیں اور ویڈیو کا اب یہ میتھر بیٹنگر کیا ہے جیکہ تو اس کو پتا ہوگا کہ ٹیکسٹ فائل کا اس کو پتا ہوگا بیڈیو کا کیا ہے؟ ماستھڑ کے لئے پیڈیو کا کیا ہے؟ کیا ہے؟ کیا ہے؟ کیا ہے؟ کیا؟ کیا؟ کیا؟ کیا؟ کیا؟ پہ چلتے ہیں ایک ہے ھا کمپریشن ویزٹر یہ بھی ایک طرح کا فائل سسٹھم ویزٹر ہی ہے یہ بھی تین مہتھر لیتا ویزٹ ویزٹ تینوں کو ویڈ کرتا ایک بر ٹیکسٹ فائل ایک بریمچ فائل و ریکبار ویڈیو فائل اور اس کو پہ دا تینوں کو الگا لگا لگا کمپریس کی سے کرتے ہیں آپ کو پہلے الگا لگا لگا لوجک اب ہم نے ایک لازم لگ دیے پہلے اپنی الگا لگا کلسس میں تھی یہ پہلے والا مہتھر جو ہوگا اپنے ٹیکسٹ فائل لازم ہوگا یہ دو پہ دوسرا ہولا مہتھر ایمیچ فائل میں ہوگا ویڈیو فیریک اور ہم نے ایسے ویڈیو فیرس کنگ ویزٹر منا آئیس کے بات بھی تین ویزٹر مہتھر ہے ویزٹ ویزٹر ویزٹر اور تینوں کو پتے ہیں کہ اپنے اپنی فائل کے لیے چاہ وہ ٹیکسٹو ایمیجو ویڈیو کو ویڈیو کو اس کو ویرس کے لیس کنگ کیسے کرتے ہیں چکے اب اپنے مین کور پے چلتے ہیں دیکھا ہم نے کیا کیا ہم نے پہلے ایک فائل سسٹا مائٹھا میمیچ فان بہنے ایسے ایمپلٹ جبی جیلیٹسے اور ہم نے پہلے ایمیچ فان پہلے ایک سب کل کیا سائیس کلکلیٹر ویزٹر فیر کل کیا بھی ایک کمپریشن ویزٹر اور فیرک اور کیا ویرس کن ویزٹر تو تینو ویزٹر ہم نے ہم نے کارل کر دیا دیا ایک ویڈیو بنای اور ویڈیو پیم نے صرف کمپریشن ویزٹر کارل کیا تو ایک بہت ہم اس کو رنگ کر کے دیکھلے دیا تو یہ دیکھا کلکلیٹر کسیسٹو ایمیج کمپریشن ویڈیو کمپریشن اور فیرس کنگ اور فیرلاشن ویڈیو کمپریشن سمپل تو یہ تھا ہمارہ پورا کا پورا کور اب چلتے ہیں کہ سٹینڈڈ ایمپلٹ پہ یہ ہے اس کا پورا کا پورا shtndd u ml diagram بہت سمپل ہے ہمارے پاسے خیرار کی ہوتی ایلیمنٹ کی اور ایک خیرار کی ہوتی ہے ویزٹر کی تو ایک ہمارے پاس I ایلیمنٹ اس کے پاس I ایکی مثلگہ except اس کے پاس ہمارے پاس ہونگے конкретی ایلیمنٹ جیسے ہمارے پاس کیا داکیمٹ ایلیمنٹ وہ پیرنٹ لازتی اور کرھے کریت ایلیمنٹ کے جیکہ کیا پاس کیا ٹیکٹٹٹھ پیل تھا, vd-o-file تھا, امیجیس تھا, تو یہاں پہ نرک دیے, конкрет ایلیمنٹ, جو کیا کرے گا, overwrite کرے گا accept کو, ایک visitor لے گا v اور اندر کیا کرتا گا, v.wz this, بس یہی کام کرتا گا. فیرہ مُس کے الگ الگ visitor بناتے ہوگے, ایک ہماری parent class و گئی i visitor, جس کے پاس ایک methoda, کیوں کی اس کے پاس ایکی ٹائی پہنے. اگر اگر یہ لکھتے دو سب دائی پھو thay, تو یہاں پہ دو visit مستھہ، اگر یہاں پہنے ایکیت ہے دیکھا ہے. تو یہاں پہنے ایک methoda, جو یہاں پہنے اللہنا یہاں پہنے اللہنا یہاں پہنے اللہنا اور اس کا��ی ایک visitor اگر یہاں پہنے اللہنا پہنے اللہنا پہنے اللہنا 1 конкрет элемент کے لیکنкрет элемент 2 کے لئے Simple اور ہم نے کیا بناہ بیچ مناہ قلاید جو ایس اپلگیشن کو ایس کرتا ہے انگی قلاید has an element and client has a visitor also چکہ اور اس طرح سے یہ دونوں آپ اس میں لنگ ہوتے ہیں Simple چاہلو اب چلتے ہیں اپنے فرق کی طرف جس پہم نے بات کی دی کی stratage design pattern اور visitor design pattern کیا فرق ہے اور وہ similar queue لگر سکتے ہیں چکہ اسے پہلے نا ہم AnotherDRG ιве گ sto ایک ایک썸 تائر wann فرق تراث تو دیکھو, ہم اپنے دبلڈیспیچ کو سمچھتے ہیں اپنے ہی ایک زمپل سے جو میں آپ ایک زمپل ہی آواتھا دیکھے دکیمینٹ ایمینٹ کا دبلڈیспیچ بس یہ بتاتے ہیں دبلڈیспیچ کی دو ریفرینسز مل کر کے ریفرینس 1 اور ریفرینس 2 مل کر کے دیسائد کر رہے ہیں کی کون سمیتھڈ کال ہوگا کیا مطلب اس چیس کیسٹیس کا دیکھو, اپنے مین کوڑ میں چلتے ہیں کیا مین کوڑ میں کالکہ تھی ہم نے کچھ دکیمینٹ کی کچھ عبجگنایتا فیلوان ایک گلٹو نیو تیکسٹ فیل آپ کو بتایں اور فیلوان ایک کچھ دیکھا اور یہاں پہاں اس کو ایک بیزرر پاس کیا تھا تو لیکھ سے ہم نے بیزرر پاس کیاسائیس کالکلیٹر بیزر یعنی کی یہ والا بیزرر تو ایک تو ہم نے ہم نے ہم نے ایک ریفرینس پاس کیا تو یہ ہو گیا ریفرینس 1 کیا تو ریفرینس 1 اب اس کا accept call اب اس کا accept کیا کر رہا ایک او ریفرینس 1 لیکھا ریفرینس 1 تو اس کو ہم نے بولا ریفرینس 2 اور یہ ریفرینس ریفرینس 2 کی ایسائیس کالکلیٹر بیزر میں کون سا بیزرٹ میترکال ہوں چیے کیسے دیکھا یہ کر رہا v.visit تس یہ کرتا میں تسکتا آپ میں لکھا بیواتے کو v.visit تس اب اس نے v.visit call یعنی کی پہلے تو ہم پتلکہ یہی والا بیزیٹر کال ہوگا کیا میں اس بیزیٹر کی بات کر رہا یہ جو v.hi یہ والا بیزیٹر ہے کیا ہم نے اس کو پاس کیا تھا نیچہ رہا فرنسے جو رہا فرنس 1 اب جب یہ والا بیزیٹر call ہوا اس میں سے کون سا بیزٹ میتر call ہوں وہ بتا رہا ہے یہ دس کا رہا فرنس ہے نا کیا یہ ٹیکسٹ فائل کا رہا فرنس ہے تو یہ نی کی پہلے والا میتر call ہوں اور 3 نوں میں 3 نی ویزٹ میتر ہے ہمیں کیا سے پتا کون سی ویزٹر کا کون سا ویزٹ میتر call ہوگا تو یہ 2 رہا فرنسے مل کر کے بتائیں گے ایک جو تو ہم فائل وینٹ ایک سیٹر پر میں ہم ایک ویزٹر پاس کریں گے وہ بتا دے کا کون سا ویزٹر call ہوگا اور یہ جو ہم دس کا رہا فرنس پاس کریں گے یہ بتا دے کا کون سا میتر call ہوگا اور اسی کو گیتے دبل диспatch سیگل диспatch کیا ہوتا جنرلی جب آپ ایک سیگل رہا فرنسے دیسایٹ کر لیتے کون سا میتر call ہوگا وہ سیگل диспatch ہوگا اور جنرلی زادتر ہم سیگل диспatch یو اس کر رہا ہم تک کیا پر اسم میتر دبل دسپچ یو اس کر رہا پہلی ہم بیزٹر پہ چانتے اور فیسٹر میتر پہ چانتے پہلی ہم رہ法 اینس رہ法 اینس ٹورتگ جاتے اس کو گیر آپ دیانسے دیکھا ہم رہ法 اینس ٹورتگ جاتے اور فیر رہ法 اینس ٹورتگ جاتے بیسکلی تینیسی باتے اس کو فعلتو میں کمپلیگریٹسا نام دیرکہ دبل диспatch کچھ نہیں ہوتا بسکلی ہم ٹور رہا ہم ملکر گی دیسایٹ کر رہا ہے کون سو வیزٹر کون سو வیزٹ مدھر کال ہونے والا ہے that's it چیگے چاہلو اب چلتے اپنے σٹریٹے جی اور வیزٹر کے فرق کی درف اب دیکھو دونوں میں فرق سمجھانے کے لینہ ہمارے پاس ایک σٹریٹے جی پیٹن تھا اور ایک بیزٹر پیٹن تھا σٹریٹے جی دن فرق ہم نے سپ سے پہلے بڑا تھا ہے نا دونوں میں فرق سمجھانے کے لینہ ایک بیزٹرٹی جی پیٹن میں لیو ایک بیڈیار ایک بریوز کرتا اُس میں ہمارے پاس کیا تھا ہمارے پاس ایک ای روبوٹ تھا اگر آپ کو یادو دون چیگے اور ہم نے کیا کہا تھا اس کے پاس الغلق σٹریٹی جیز ہو سکتے ہیں تو لیٹھ سے ایک تھا بیحیویر ای فلای σٹریٹی جی چیگے تو ای فلای σٹریٹی جی ای فلای بیحیویر کیا ہو سکتے ہیں اس کے بھی ہم نے کہا تھا ملٹیبل سب ٹائی بوزکتے ہیں تو اس میں تھا لوگہ لیٹھ سے فلای اور اس کو یہ اپسٹیگ توگی کلاس اس کو اووورائٹ کرتا ہو آپ کو یادو دون یعنہ یہ ہم نے دکس کیا تھا اور اس کے بہت سرے سب ٹائیپ سکتے ہیں ایک لیٹھ سے کہا تھا فلای بید وینگس یہ ایک سب ٹائیپ تھا ایک تھا لیٹھ سے فلای بید جیٹ یہ ایک سب ٹائیپ تھا وگر آپگر آپ تو بارے بہت سلک لیکن سب ٹائیپ تھا اور یہ روبوٹ کیا روبوٹ کے بات سرفرین سوتا تھا اپنی سٹریٹیجی کا یعنی کی روبوٹ کے بات ایک ای فلای بھیحیر کائی کبجیکٹ ہو گئی ایسٹریٹیجی کائی کبجیکٹ ہو گئی لیٹھ سے ففس اور اس کے بھی ایک مثھا دوگہ فلای جو کیا کرتا ہو گئی دیلگیٹ کرتے ہو گئی تو وہ فلای .
Sorry یہاں پہ جو سٹریٹیجی اپس دوٹ فلای کل کرتا ہو گئی انٹرنلی یہ سب امنی دسکس کیا دا اب دیکھو ویزیٹر اور سٹریٹیجی میں فرق یہ ہے اور اگر آپ کے سمجھ نہیں آرہ کی فرق آکی ورنس کے بارے میں بات کی کی جاری ہے تو اپسے سمجھ لو کی سٹریٹیجی تو یہ کہتا ہے کی ہم کیا کرتا ہے ایک سٹریٹیجی کے پاس ملٹیپل طرح کے بھیحیر ہو سکتے ہیں فلای ای فلای سٹریٹیجی فلای ویدویگز فلای ویدو جیٹ ہے اور یہاں ایک ارطرقا فلای بھیحیر لیکی سکتے ہیں فلای ایک ارطرقا فلای بھیحیر لیکی سکتے ہیں اور ویزیٹر کہتا ہے کی ایک ایلیمنٹ کے پاس ملٹیپل طرح کے اپریشان سو سکتے ہیں جو میں دکیمینٹ ایلیمنٹ والے ایک زمپل لیا تھا جو میں ویزیٹر سکتے ہیں اسم امرپس ایک تھو تھا کلکلٹ سائز ایک تھا کمپرس اور ایک تھا مارے پاس ایک تھا مارے پاس scan 4 virus scan لیکن دیتا ہوں میں تو یہ میتھرز بڑھے جا رہے تھے تو کچھ لوگ سوچ سکتے ہیں ہم ان کی strategy اس کیونی بڑا سکتے کلکلٹ انسائز strategy компressing strategy scanning strategy اب اس کا فرق سمجھاتا ہوں دیکھوں جو strategy design pattern کہتا ہے نا وہ یہ کہتا ہے کی ایک robot کے پاس number of operations same رہیں گے number of operations یعنی کی number of behaviour یہ ہم اسے اسکتا ہے number of behaviour جسے fly ایک behaviour ہے let's say talk ایک behaviour walk ایک behaviour یہ تین behaviour یہ نمبر of behaviour same رہیں گے ایک robot just fly talk and walk that's it just fly talk and walk but کی طرف وہ fly کرے گا اس کے طریقے بڑھتا ہے ہوں ویڈ بڑھنگز کرے fly with jet nor fly same طرح سے talk نورمال talk or talk جو بھی امنا اسم تسکس کیا تھا ایسے ویکن کے بہت سرے طریقے ہو سکتے ہیں تو میں یہ کہتا ہے number of behaviour constant وہ چینج نہیں ہوں لیکن چینج کیا ہوں طریقے اس بھیئے کو کرنے کے چینج ہو رہیں اسے لئے ہم نے strategy کو انترڈیوز کیا تھا کہ ایک ہے ایک ہے iFlash strategy اب ویسے یہاں پہنے ہمارے پاس ہو گا ایک i talk strategy اور ایک ہو گا iWalk strategy اب یہ تو 3 class constant رہے کیا کہ ان iRouboot کے پاس 3 او کے reference دے اسلے مجھے یاد ہے strategy design pattern ke YouTube comments میں نہ بہت لوگ نے یہ بھی comment کہ لیکن کلکہ ہم ایک new behaviour لیاں swim نام کا behaviour فر تو ہمیں class میں چینج کرنا پڑ جا گا ہے iRouboot کیا اب اس کے پاس 2 ref 3 reference iFlash strategy iTalk فرمیں اسی class کردر جا کر کے open close principal break کرنا پڑے گا اور iSWM strategy لڑھا پڑے گا تو میں وہاں پہ بھی بھی بتانا چا رہا تھا کی robot ke pas ہم یہ سوچ کے چا رہے کہ number of behaviour change نہیں ہوں گے کیا کہا کہا کہا کہا کہا کہا کہا کہا کہا کہا ہمیں باتا ہے ہمیں اپلیکشن کو بناتے رہے تو ہم control کر سکتے ہیں کہ ہماری اپلیکشن میں کیا change ہوگا کیا change نہیں ہوں گا اگر آپ کو پتائے کہ آپ اپلیکشن میں number of behaviour gaonstant rehnne walea bus اس behaviour کو کرنے کے taryke badaalne walea تو strategy pattern use کیا کہا کہا کہا کہا کہا کہا کہا کہا کہا کہا ki tene strategy i fly iSWM or sorry iSWM iTalk or iBOK but ngo karne ke taryke badaaaheng ki aa ki aa ki aa kha msi subclass kha aa nae aa kha msi subclass اگر امیسی روبرٹ پیزیٹر پیٹل لگاتے تو یہ جہاں امیسی روبرٹ کلاس ہے ایس کلاس کے یہی فکس نہیں ہے نمبرٹ بھیحیر سے فکس نہیں ہے اب یہ فلای کر رہتاک کر رہتاک کر رہتاک کر رہتاک کر رہتاک کل کو لٹسے یہی سویمی کر رہتاک ہے اہنا اس کے بعد لٹسے کوئی اور اپریشن بھی کر رہتاک تو کچھ بھی اس کے نمبرٹ بھرچنز بڑھے نہیں پر اس کو کرنے کے طریقہ ایک ہیوں ایسا نا اس کے کرنے کے طریقی بچاس ہے اوس کے کرنے کے طریقی بچاس ہے اوس کے کرنے کے طریقہ ایک ہیوں تو ہم اس کے اس میں ایسے میں ایسے میں ایسے دیزائیم پیٹن کیسے ہم کیا کریں گے ایروبرٹ کو اپنا نورمل کلاس بنا کر کے اس میں ایک مدھر دلتے ہیں اور وہ ایک ویزرر لیتا ہوگا ویزیٹر بھی جسی اب یہ مروبرٹ دیکھا تھا تو اگر انس کو سمپلی لگنے جو ایک ویزیٹر لیتا ہوگا ویزیٹر بھی اور آپ کو بتے کیا کرتا ہوگا یہ وییدارٹ accept call کرتا ہوگا خودگہ referenceے کے اب ہم نا کیا کریں گے ہم الگ الگ ویزیٹرز بنالیں گے جسی کی فلای ویزیٹر ایک فلای ویزیٹر نام کو اپجک کرنے اوس میں ایک مدھر لگا ویزیٹ اور وہ حندل کریں گا کی کروبوت فلای کیا کرتے ہیں ایسے اب ہمیں ایک بنالیں گے بلکھل گا اس کے لیسیٹر پیٹن میں پر اگر لگا لویزیٹر پیٹن نہیں لگا پارے کیا وہ بھیائے بھی چینج ہوگا اور اس کو کرنے کے طریقے بھی چینج ہوگا تو اوس تردیجی برافر کرتے ہوگا اور آپ تریدف لے لیتا ہوگا کیا وہ بات نی اوپن تو سوڑا سوڑا سا بڑے بھیائے بے چینج ہوگا وہ تو دخول ہوں سمپل لگے گی سنپل لگے گی سنپل کریں گی وہ کچھ ہی சاما جا جہے گا. Vizitor thola sa complicatedo jai ga Ondono scenario's mein. Jahape problem's vi changeo riya sorry. Behaviour vi changeo riya.
Aur ongo karna ga tari ki bi changeo riya. Tega. To that's it. Abe ek bhar's ki standard definition dikt hai.
To deko iss ki standard definition bhaat simpalin. Allows to add new operation to existing classes Without changing their structure. Right. Abe karna waay kar reay te.
Ame klas ke enda naay operation saay te kartsak saay te. Bina usko change kare. Separates operation from the object it operates. Right.
Usthe operation saay te separate kare te. Alla ghalag vizitars bana kare. Ta ki issme eki metad rai accept. Right.
Aur ham isko bhar bhar naa te de. To that is the standard definition. Agar am iske real-world use ke ski baat kare na. To ye use ota khaskar, Jahape game rendering engines mein.
Yuki us mein aa bhoot saary operations ote hai. Right. Usthe render hoota hai. Usthe me let's say map fetch karte ho aap.
Right. To bhoot saary asya operations aa perform karte rai te. Ujho bhar te rheenge. Throughout the time.
Aur aap ni jadeh ya bhar bhar klaasis ko change karo. Ski ke. Iske laava iske use hota hai ki si bhi compiler me. Abhi iske ye wala use hoota sa complicated hai.
Jabab padho ke compiler in dar se kye se bhante hai. Jahawa ka si plus plus ka. To ka saama jaha ka ki usme aeshti hoota hai. Right.
Aur aeshti ke ota kuchni hoota kte trees hoota hai. Ki jobi aap basically operations ya code likte hoota. Usthe ko vak tree stuqtchara me denot karte hai. Usthe ko je bhaap travers karte ho.
To aalag alag visit operation koal karte ho. Aalag alag operations ke liye. Mutla bki wards ke liye. Sindh tekks ke liye wakarav ka ara.
Toh da sa ye complicated hai. Iske baare mea padas akta ek baar hal nain. Par main liye gaaraf samjo to game rendering in jadeh mea sa kha baat use hai. Jabne se egzampa liye je sa document ko aalag alag tari ke saay.
Usthe ko operations perform ka na. To aise ka koi bhi use ke. Jisme operations bhaar rahi hai. Basically number of operations bhaar rahi hai.
Par uske karne ka tari ke. Allmost eki daay hai hameisha. To whaap yaa visi nal pata ni use kaar rahi hai. Allo kaafi use ke specific hai.
Bhood kaam problem sa hai. Aap ke real life use mea jhaap hai aap ko ko aalag li problem dea aur visi nal directly lagi hai. Par jhaap hai bhi aap ko aasi problem mil jai hai. Jhaap hai nambar aur operations same nahi hai.
Vahap hai aap visi nal use kaar saak teo. Infact aik ka bhood aagag gyi mein karsak teo. Aap na interviewer ke saat ki aap hai baay mea visi nal use kaar rahi hai. Aap na interviewer ke saat ki aap na visi nal use kaar rahi hai.
Bhaak hiis video mea it nahi. Aap sa milta hai next video mea. Tapta geli thank you so much.
Lesson FAQs
What is Visitor Design Pattern | UML + Code | System Design about?
حنجی تو کرے شاٹ, Welcome Back Coder Army our Celestial D series and today we have brought a new and easy design pattern which is called Visitor Design Pattern Now what does this design pattern say? And how does it compare to other design patterns
What key concepts are covered in this lesson?
The lesson covers visitor, design, pattern, code, system.
What should I learn before Visitor Design Pattern | UML + Code | System Design?
Review the previous lessons in System Design Full Course, then use the transcript and key concepts on this page to fill any gaps.
How can I practice after this lesson?
Practice by applying the main concepts: visitor, design, pattern, code.
Does this lesson include a transcript?
Yes. The full transcript is visible on this page in indexable HTML sections.
Is this lesson free?
Yes. CourseHive lessons and courses are available to learn online for free.
