Proxy Design Pattern - The Heart Of Spring Framework (AOP) | Dynamic Proxy | Design patterns in java

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back my name is avilas you are watching selenium express and if you just found this video from a youtube search you might be looking for a topic called dynamic proxy or maybe proxy design pattern and if you're looking for the same go for the dynamic proxy with this timestamp and the proxy design pattern will be available in this timestamp but if you're a subscriber of this particular channel holder i have something to share with you so we are going to start a new series over here called the transaction management in spring and for this we need some prerequisite and the prerequisite will be spring of course and if you guys are a subscriber of this channel most probably you should be our with the spring framework but one more prerequisite that we need over here is called the dynamic proxy and that's why actually i'm making this particular video so to understand dynamic proxy you also need to understand proxy design pattern so make sure use this video as the predicate before you jump for the next video in this particular series which will be on the transaction management topic spring framework i hope you are excited because this is one of the very important module of spring framework where you will be it's not a module it's obviously some concept but this concept is pretty much required required for your real-time project as well as for your interview preparation and hopefully you guys are a banking domain or a insurance domain or a sales domain or maybe you know something related to e-commerce if you are like you know working on this kind of project make sure you should be good with this particular topic so use this video at the prerequisite or if you have already the prerequisite just switch off relax sit back and maybe just wait for the next video which i'll be uploading shortly but right now it's time for the proxy design pattern in java so let's switch to this particular topic and i'll see you in the video [Music] all right so basically i don't have time right now to record the video uh of this particular topic so what i'll be doing i'll be using some of my recorded session that i have took in one of my live boot camp maybe so i'll be using those videos over here so you guys can watch this video anyhow for you guys it will not be a matter but yeah i have used some of the recorded session from one of my boot camp over here so hopefully you'll be finding it helpful and if you find it helpful and if you're more interested for topic like this keep me posted with the comment in the comment section perfect so right now before we go for eight transactional annotation so for this week we'll talk about a transactional annotation a lot of in-depth deep dive we'll be doing because it's a very important topic to understand and to do the day-to-day job as well as you know if you want to click clear your interviews it is going to it is going to be pretty much crucial because you're going to be getting so many different types of questions from this particular topic okay so what i'm planning to do before i jump to a transactional and before i start implementing various different things i also want to give you some prerequisite i don't know if you have it or not because few people like you know you got some good amount of experience seven plus six plus nine plus but people who are like you know just getting started with java maybe this is going to be useful for you because i'm not sure if you already got this concept or not this is basic core java concept but let's try to brush off our things first and then we'll go to a transaction now uh to the transactional tomorrow because the things that i'll be doing today tomorrow i'll be like you know using it uh pretty much so make sure that you put all your concentration right over here okay before we go for a transactional annotation anyone um anyone recall like the how spring is how spring is managing the transaction behind the scene what concept it does uses behind the scene anyone wants to give any answer to me what kind of concept or technique spring is using behind the scene to do the transaction or to maintain the transaction anyone okay yeah i think some proxy proxy okay what kind of proxy there are many type of different types of processes in it uh virtual proxy remote proxy protection proxy um you know but specifically i remember you told something to either a transactional it it uses some uh some proxy pattern behind it yeah because if anything goes wrong it will automatically roll back correct and uh correct yeah that is very minimal kind of thing that we have done previously yeah that's correct that a kill uh proxy is the pattern to use just behind the scene and also we in spring uh basically is uses some technique cross-cutting technique uh what is that how we will be basically achieving the cross cutting technique in spring if you remember okay spring aop spring aop with the aop right correct and uh you will have cross cutting concern and uh active uh what was that i i forgot the names of you yeah no problem cross-cutting concern because see the thing is that uh if you're gonna learn a transactional annotation you'll be learning you you have to learn a little bit about aop because spring will be doing those uh you know transactional stuff behind the scene by using the aop and if you're gonna learn aop the way your aop works by using proxy okay and what kind of proxy and there comes a term called dynamic proxy and today we'll be talking about dynamic proxy in java how we'll be creating the dynamic proxy but before we talk about dynamic proxy we got another word proxy what do you mean by that i don't want to go so in depth of it that's a design pattern we can talk about that a lot uh in our future design pattern courses but now i want you guys to give me some specific answer what is your thoughts about proxy anyone what do you think about proxy lavenya proxy when you hear this word what do you think about it um that actually be a substitute or a placeholder for any kind of other objects exactly right answer so it's basically uh basically proxy is a pattern when when someone say a proxy is something like on in v of right or in place of right so you don't want to call i don't want to call or kill directly i will tell lavanya that hey you call or kill right this is the same thing if you remember guys in your in yours you know schooling days right so uh you used to be get late right and used to tell your friend that hey go and you know give a proxy for my attendance right and your friends used to give a proxy attendance whenever your teacher calls your name that hey uh whether that guy is present and your friend used to say presents up right so basically that's a proxy and when actually the teacher called your name and he calls your name and he he basically uh tell you to you know go to the go to the board and draw something your friend make a call to you that hey your teacher the teacher calling your name and he's asking you to asking something to draw in the blackboard or in the whiteboard and you used to used to have a backdoor entry and used to you know go to the board and do the work by yourself so your pain here is a proxy because he is actually calling you your teacher is not directly calling you your teacher say hi and your friend actually replied and when your teacher actually looking for you your friend is actually giving a call that hey now your physical presence is needed and now you are going back to the board and drawing something right there so this is going to be a very nice example uh sonic is saying it is an extra layer before reaching to the main service object exactly pinpoint answer so basically if you're going to see this um you know i have written something so proxy design pattern whenever we talk about the couple of different things we talk basically uh in place of or in behalf of this is the exact meaning of proxy or some literal meaning of proxy if you're gonna think about the proxy design pattern so it's pretty simple previously we used to make a direct call to the object and this is our real object from our client we make a direct call to here but if you're going to use the proxy pattern this is your client you make a call to the proxy and the proxy make a call to the real object this is just one extra layer asomic said we will not be directly hitting the main real object or our service object we will call our real object or maybe treat this as a service object a service service class where our business code will go imagine here is your business code but before someone will make a call to the business code there is one extra layer and here you're gonna do certain stuff maybe you can check whether this client is a valid client or not you can check whether this client got a valid ip address or not should this should we actually pass this request to the real object you can check over here like which the client is basically coming in how many times is hitting our service you can lock you can trace you can do whole variety of things you can implement security you can do a whole variety of things right over here inside the proxy layer because before you make a call to the real object you're going to be maintaining all sort of extra stuff right here inside the proxy okay so basically uh it can you can treat like you know yourself and the bank if you're going to go to the bank directly and gonna withdraw some cash um this is like you know you are going to bank um you are driving to the bank you are withdrawing the money and things like that so if you're gonna see this one this is you and this is the bank which is the real subject but in order to interact right now you need an atm machine and this is a proxy you don't have to go to the bank directly you go to the atm and withdraw the money and whenever you're withdrawing the money the atm is basically contacting to the bank and giving you back the cash right so this is something that i want you to do with the court and maybe we will uh i i will just give you one um we'll do one program right now and i'll give you a couple of assignments to do so let's create a very simple java project no springboot project very simple java project here okay and i'll give a project name as let's say um proxy and i'll do a finish okay uh i'll not create one question yeah okay when you say when you say talking about transaction management you mean address transactional at the right transaction but we will come into that at the right transactional has various different things it's not only the annotation that you are seeing at the transactional it got propagation level isolation level you know a lot of different things um we can talk about you know in that particular chapter but before i implement those things okay um i will be using some certain things which is going to make you guys uncomfortable so before you know in order to like you know before we do certain stuff let's try to understand the prerequisite first okay and with this class it will be comfortable and from tomorrow onwards we can start directly implementing the dynamic proxy we can do whatever like you know because see okay if you want to make some call using spring spring gonna use something behind the scene and if i'm gonna address those things directly maybe you know it is gonna it is gonna be you know tough to understand if you never experience those things so i'm going to be doing few things today and i want you guys to practice the same thing uh maybe today itself and from tomorrow onwards things will be pretty much easy and you don't have to go and check here and there that what obvious is saying or you know i'm not able to catch his words or something like that okay so the main intention of today's class is is to learn dynamic proxy but before i go for dynamic proxy i want you to i want you to do a simple program with proxy so that everyone will hour oh it's a very simple thing so guys imagine the same example that i have given you like you know you your friend um your friend will give the proxy for you when the teacher calls okay same thing let's let's do some some same things like this so maybe what i'm gonna do i'm gonna create a new [Music] let's say a new interface and let's say this is going to be a you know daily let's say interface name will be daily session okay do we finish and let's say there is a interface called daily session and i got a method here called attained lesson okay so let's say there is one simple method here inside a inside a interface called daily session and let's say a student want to attend everyday session okay and so if a student want to attend he has to override this method and need to give an implementation so i have a impul class for this daily session let's say a student right and the student let's say is going to implement the daily session and he got to override the unimplemented method and let's say here i can just have a simple log for now let's say uh attending uh attending the session okay let's say the student is attending the session we got a very simple thing over here and let's say in order to attend the lesson as i said the student has to give the attendance so maybe i can create a uh attend tense uh object here okay and i don't have a class called attendance so let me create it quickly here inside the same package and inside the attendance let's say i got um a couple of variables let's say to this date i'm gonna be tracking private date let's say date for the today i'll do control shift o import the java.util.date and another one let's say private uh boolean let's say present okay if the student student is present or not and maybe i can say is present if you're gonna if you are not able to understand present this is going to be more readable i'm gonna say is present okay and let's say we have a constructor to initialize this couple of things so source i'll do generate so there you go so i got a constructor in order to initialize all these variables which is present over here okay so now if you're gonna go to the student so let's say um obviously the student need to give the attendance so let me just create a constructor so constructor using field do generate and now you can see that i got a constructor here inside the student class control a control shift f so if um you know you want to build the student object obviously you'll be using this constructor and you need to pass in the attendance object so if the attendance is there then only you know he'll be able to attend the session let's say this is the logic that i want to build but the problem here is that let's say i have a main class right let's say this is a teacher class and this is like this is my client right this is my client class let's say i have a main method and this client who is my teacher want to want to uh you know build the object of the student let's say student student is equal to new student right and he has to give a attendance so new attendance here and he has to pass a date here let's say the date is today's step that's a new date okay and uh the next thing is whether he is present or not as i have told you attendance got a couple of things state and is present and he is present is bullion so it is gonna take true or false if he is present then it's true if it is not present then it's false let's say it is true all right so now we have built a student object you can take many variables here like the student name id and blah blah blah stuff i'm not taking those things uh just trying to uh you know prove my point here so now you can just call the ad adolescent method and obviously you know adolescent method will be uh giving you these things back so if you're gonna go back to a right click run is java application you will be seeing that um we will be able to call the method and it is saying that attending the lesson because the student is present here okay what about the student is not present and i'm gonna change it back to false and now if you're gonna do a run is java application you're gonna see still we are able to attend the lesson the student is able to act in the lesson even though the student is not present so now here what i need to do if i want to implement the logic like you know if the student is not present then he will not be able to act in the lesson then how we are supposed to you know achieve that thing you'll be saying okay let's just pretty simple go to the attenuation and you can drop your code right over here and this is something that i don't want to do because there can be many client there can be um maybe i will come back to this particular point but here i will not be draw i'll not be dropping my code over here rather i'll create a proxy as i have said i will here i'm doing this right i am making a direct call i'm making a direct call like this uh see like like this now i want to have one extra layer like this i'm gonna make a call to the proxy the client is gonna make a call to the proxy and the proxy is gonna matter call to the real object and in order to do that here in the proxy i'm going to be creating a new class and this is going to be a proxy class let's say the proxy class will be same as the your base class i'm going to say student proxy it's gonna look pretty much familiar student proxy do finish and now here i'm gonna extend to the student class itself right so i'm going to inherit all the properties from the student class it is asking me to override the constructor let me do that so that it will call the superconstructor and the next thing is that i'm going to do a control space i'm going to overwrite this method but here i i want to do what i want to call the super class attenuation method now you can see i am inside inside the student proxy method i'm actually uh overriding the attenuation method because if you remember inside the student class i got a attend lesson method i'm overriding that and then i am calling the super class attenuation method that means this student class attends attenuation method i'm calling if you're gonna click over here you'll be reaching that animation method of the studying class right so i'm uh you know establishing a new layer in between the client and the student which is going to be the student proxy but here i'm not only going to call the you know original object rather i want to do some check what kind of check like if okay and i can do if um so i i basically want to do attendance what is that can i go there yes attendance i don't have a getter and setter isn't it create getter and setup okay go back um and here can i do [Music] if super dot i'm gonna say super dot get attendance if this is true then only call this guy or else you know we're gonna throw exception else we're gonna throw new runtime exception and we're gonna say that um student is not present and can't attend the lesson correct right so it's run time exceptions something else was there okay run time exception right this guy control s so what is happening here change the return type to boolean so get attended get attendance dot get dot get oh okay okay okay one second one second attendance uh get attendance oh yeah so we need to have a hold of this guy right okay let's let's do like this super dot get attendance dot is present get attendance dot what is this getter and setter method there is o is not there can i have the getter n setup for this one getter n setup for each present so that i will be able to access this is present right here so super dot get attendance dot is present okay if this is true then you know attendation if it is not true then just throw a runtime exception so i can just end it over here and let's try if it is working right so right now i can go to the like you know to the main class which is the teacher class and right over here the teacher will not uh you know create will not directly interact with the implementation which is your student object right now he will be talking to the proxy right so here i can just do student proxy instead right and i'll import this one and there you go and now if it is false now i think we'll have our validation will trigger and this is gonna tell us that well student is not present and cannot attend relation now if you're gonna make it true obviously the validation will say that okay the student is present then the things will work fine okay attending the lesson is the answer and if you're gonna make it false obviously you know it will not work so i just want to tell you with this particular pattern is that right you need to call the student proxy from the client your client is your teacher and you are calling the student proxy directly not the student object directly so we are actually dealing with a proxy object rather of a original object but whenever you are dealing with the proxy object let's say student student or maybe you can um maybe you can just uh change the reference to your you know daily lesson that's also fine you can just make it daily lesson [Music] okay and daily relation with the small copy this guy paste it over here now i'm directly coding coding into the interface let's see whether this guy is working and of course you know we we're gonna get student cannot attend the lesson because he is not present and if you're gonna make it true this is gonna work fine so we are actually having one more layer established between our real object which is the student object and then the student proxy so this is one guy over here and this is one guy so this is the original one and this is the proxy one okay and you can you can see the proxy attenuation method is making a real call it is calling super dot attenuation because the proxy is right now exchanged to the student okay hopefully this is making sense this is called protection proxy i don't want to go very detail into that but i want to just let you know about the definition of proxy if you're going to look at the definition of proxy right now so it provides an object that acts as a substitute for a real service object used by a client a proxy receives a client request does some work and then passes the request to the original object and that's what we have done and if you're gonna see over here the student proxy is a proxy object and whenever it's gonna receive the attenuation call it is gonna doing some work over here and once it is once it is like you know doing that particular thing it is basically passing the thing otherwise instead of this if else i can just do like this i can move this guy over here and move this throw thing to the if clause and if it is not true i can do these things and you can see now the proxy receives the request you can see the daily if i'll go to the client class which is my teacher it is basically calling the attenuation on top of the daily session and daily session is a proxy right now and right now the attendant lesson received the call the attenuation if you're gonna go to the implementation of the proxy is received the call does some work and then passes the request to the super class okay hopefully this is making sense right tell me yes or no if you guys are okay with this thing yes please well you guys are able to understand this thing okay okay perfect so now let's go for the next thing or something on the chart okay okay now let's go for the next thing this is after text this is what we call a protection proxy just like that we have remote proxy virtual proxy and blah blah blah stuff we're gonna be i'm gonna giving you a couple of assignments maybe i'm gonna be coming back to this thing again but yeah forget about all these things and let's start fresh right just wipe out everything i think you got a very simple understanding that is basically a in a layer between the original object and the client okay so the client will make the call to the proxy the proxy will make a call to the real subject okay this is something that i have told you now i will go back to the dynamic proxy that i am basically interested for in this lesson this is something that i want to teach not this one this is just to building the you know foundation a little bit [Music] now before we go for dynamic proxy i think there will be some term will come i will just check your understanding maybe i'll go and create a class here called a test class and now let's just try to have uh some you know a little bit of fun kind of discussion i want you to give a task okay if i want to load a class in java for an example i got a class here called student right so if i want to load this class in java then how can i load it here in this method in the test class i want to load the student class or the teacher class or the student proxy class or many any java.util.date string class if i want to load any custom classes or any predefined classes in java what is the method i have to use in order to load a java class anyone hey don't send me that you don't know this one lavanya nagasri prashant yes yes that's what i want to hear class dot for name right class dot for name and you have to give your package name over here so let's say i want to load this class then i can copy the qualified name of this one and can paste it over here guys this is not related to proxy or something right i am just trying to refresh your you know concept of the topic reflection a little bit more if you don't know reflection also don't worry maybe whatever things i'm gonna be discussing right now that will be well enough now i have just asked you a question that if i want to load any kind of classes in java then how can we do it so clash dot foreign name is something lavinia said and of course this is the right answer using this guy if you're gonna do control one assign statement to the new variable over here and i can say uh class information now this is my student info so now lavena can you tell me what this student info will contain now i'm loading the class that means what the class will contain one have the class in the in the class path i think yeah i have the class in the class path here here it is you can use the functions of that exactly exactly loading something if you want you want to load something you want to load data so what is the data content obviously the information about that class so whenever you're going to do class dot for a name what it is going to give you back it is going to give you back about the information of the student class like well the student class maybe i will not touch this package okay i will not touch this package because i need to give you this one right let me say proxy it's not proxy it's basically something else that we want to learn but let me just close everything go back to source main java let me go to the test class okay now we're going to be talking about a little bit about the clustered for name okay this is going to give you the information about this class and if you're going to do control 1 assign statement to the new local variable now this is going to get you the information about student class so you can write student info here so what is the information is actually so obviously what your class will contain the class will contain constructor maybe you can have money many constructor like this an or constructor a single r constructor maybe you have two parameter three parameter constructor if you have more variables you have different methods like adolescent get attendance and blah blah blah so you you can get all this information by using this object right you guys know about this right if you're gonna do student info dot get um let's say you can see you have a lot of different things get constructors get constructors will get you all the constructor isn't it control one a send statement to a new local variable now this is gonna give you a constructor array like whatever the constructor as they are inside the class and then you can have a simple for each loop to loop over this constructor um right here and i can say i can just copy the type paste it over here and let's say constructor and you can just do a sys out and it's going to print all the constructor that you got inside the class if you're going to do a run is java application it's going to print out all the constructor here see that couple of constructor one is no param and one is which is going to take the attendance proxy don't worry about this word this is just a package name right forget about proxy right now so you got couple of constructor inside the student class and this is what it is printing and you can see this there are a couple of constructors over here this is one and this is another one okay now if you want to get all the methods now how can you do that obviously um anyone know how to get all the methods we have a class called methods yeah we have a class called method that's that is going to contain the method information so obviously the method will be get there are two methods get declared method i believe okay you can see get declared method get declared method will get you all the methods inside the class like you know even it is private public any methods will be it will give you back another one is there called get methods i believe this is only going to give you the public method so maybe i'll just go for get declared method and this is going to get you all the methods and maybe i'm going to say get declared method i'm not looking for any specific method i'm going to look for all the methods so get declared methods this is the class so this is the method and as renewable said it is going to return you a array of method this method is the class okay which is going to have the method information just like you have a class called class you also got a method called you you also got a class called method and now we're gonna get a uh you know uh array of methods now if you're gonna oh you can look over this one ctrl c ctrl v and declare methods i can loop over this one and this is going to be the type paste it over here and i'm gonna say here method and you can loop over all the methods right here and do a right click run as java application it's going to print out all the methods that you got and look at that you got three methods here called set attendance get attendance and attenuations right not only the methods and constructor you can also do variety of things you can you can basically load your annotations you can can do anything uh with the uh you know the class object that you are getting it's basically going to be the metadata uh in the class related information it will be loading over here and this is one way to load a class i think you guys know about that you got a couple of other ways for an example you already have in for an example there is there is some other way to load a class for example instead of using clustered for a name let's say if you got a string like this um a package a qualified name like this you can load the class like this right otherwise you can also do your class let's say you want to load the data from a student class so you can write student so this is a class student.class and you can actually assign this one i believe to a variable so i can write you know where v i think this is gonna work or maybe you can just this is java um you know the java feature though new recent use of recent version of java feature otherwise you can just do something like this student student and now this is going to get you the information so what is going to give you back class of sorry sorry not student it's going to give you a class of student this is going to get you the same thing you can do student dot get and you can say get annotation get declared methods you can also do get constructor you can do whatever you want to do with this guy so this one and this one are same this is with a in a string you are loading the class this is with a class if it is present you are loading the class like this or you can also do something like this if you already have an object let's say you got an object like this student student is equal to new student okay and you you got to do something like student dot class dot get class i think this is it maybe i can just do student dot class or get class and this will get you the maybe if i'm going to assign statement to a new local variable it is going to give you the class object so is if there is some wildcard entries that means um this object which is going to return to you is exchanged to the student class maybe you can remove it for better understanding for now and you can say student info right so this is also the similar thing okay i hope that that you understand and here we are basically loading the class by using the get class method previously i have just used the class name directly and dot class and this is another way um by using the clash dot foreign name you can load the class metadata information okay so just want to want you to make you familiar with this you know class that we have called class and also the various methods that we have i have one small requirement guys okay imagine i'm gonna give you one small requirement then i'm gonna be switching to dynamic proxy for an example guys i'm gonna go back to the student class this is a tax for you so i'll go back to the student class imagine i have a couple of methods let's say attenuation maybe i can have one more like one more method attenuation and i'm gonna take um integer um let's say id and i'm gonna say attending the session okay student with id let's say plus id and attending the lesson okay so let's say i got couple of method added attenuation which takes a integer as a parameter and at relation which takes nothing as a parameter now i want you guys to call this method using reflection can you guys do it okay i want to call this method because reflection is not only related to loading the information also you can make calls and for your for like you know you already know this but for your information your framework like spring java ee framework uh java persistence framework like jpa they all use this reflection to create objects and right now let's say i want to create i i want to call that particular method that i have just created i got couple of methods right now let's say i want to call this method attend lesson this method i want to create sorry this method i want to call from this test or java class then how i will be calling that particular method using the reflection just want to give you an impression that the reflection is not only for loading the classes or loading the classes like this you can also invoke the methods that you have inside your class not only the methods you can also invoke the constructor you can create objects um so anybody know how to how to basically call this particular method that we have over here how can i call this method inside this class anyone yes um anyone if you guys know supriya correct so maybe this is basically where we are basically getting the class information we can do student info dot get declared method maybe the method might be private so i'll go for the get declared method and can i find one get declared method and here you're going to be giving the method name so you'll go to your class and let's say i will be calling this method so copy the method name attenuation let's say this method copy this name go back here give the method that you want to call then then the next thing is the argument of the method so what is the argument that we have let's say we want to call this method uh sorry this is a constructor let's say we want to call this method then we have the argument called integer id then the type of the argument is integer so i'll go back here and here i need to pass in the thing and there can be many uh right now we have only one argument right there can be many argument that it can be having two parameter three parameter four parameter uh you know arguments right over here integer call comma id uh sorry integer id string name and then we can have various thing over here inside the parameter now we have only one so maybe what i'll do i'll have a class array so class and let's say r u let's say x is equal to and let me just do new class or maybe i can just do class array directly and i will wrap this up and i will be using a new c as capital and i will be basically um or i will be giving my type let's say the type sorry the arcs is already there right let's say a method asks method args type okay so now if you're going to see the attenuation right so this attenuation is going to give you what type this attenuation method got a integer type over here so now i'll go back and gonna mention the type here called integer dot uh let's say class right this is one type that we have as the method arguments i'm gonna pass it over here all right so i'm gonna get the method called attenuation just gonna throw me an exception a checked exception i need to handle that so maybe it is gonna throw you the no search method exception if the method is not found by java okay so now this is gonna get me a method right there is a um you know class called method and it is going to get you the method method information now you want to invoke the method and if you want to invoke the method called attenuation then i will be doing it you'll be doing like this method dot invoke and here you need to give two things what is the object on top of which object you want to invoke this method called attenuation next thing what is the parameter that you want to pass like we have defined here we want to call a method called attenuation and the arguments that it takes is an integer then here we need to pass in the arguments like you know integer value let's say the id is 1 zero one okay and here you need to give an object on top of which object you want to call this method now on top of which object you want to call this method on top of student object now we want to initialize the student object this is where we are not initializing it we are loading it now if you want to initialize it you can do like student info dot new instance and you can just do control one why suppress warning deprecation oh is it deprecated maybe from java oh maybe from java 9 it is deprecated so if that's fine i'm going to go ahead and keep using this one ctrl 1 assign statement to new local variable now i'm going to get an object maybe i'm going to cast it to student because this is the new instant is going to give you back an object i'm gonna cast it to student student uh this is going to be my student object copy this guy paste it over here and there you go maybe it is gonna throw you some exception i'm gonna add it to over here and maybe this is also throwing you some exception i'm gonna add it to the throws right now if you're going to ctrl s let's do um let's do run this let's see if you are able to invoke the method run this and there we go student with id 101 attending the lesson okay so um obviously right now if you're gonna go to the student if you're gonna go to um this one this is basically the log which is getting printed right now if i want to if i want to execute this one then what will happen then how can i do that if i'll go this is my method name but this does not take anything inside the parameter so i can go over here and i can basically load this method right so i can copy the same you know line from here paste it here ctrl x this one paste it here the method name is same but there is no method argument type i can remove the argument type because it does not take anything in the parameter and i'm gonna say method one let's say and now i can invoke it method one uh dot invoke and i'm gonna invoke it on top of this object called student and the there is no uh argument type so i'm i can basically pass in null over here i believe because obviously i don't have any any parameter here in this method called attenuation if you're gonna see here attenuation does not have anything inside the parenthesis right here so i can i can go like this one right or i think this is this is fine okay can i do right click run is java application and this is just giving me attending the session i just want to drag your attend attention to this method called you know the way we are basically invoking the method the way we are getting the method right here using the reflection technique and how we are executing the method using the reflection now guys if you remember uh in your java e in your spring framework used to configure dispatcher servlet right how the dispatcher sublet is getting loaded right you are just mentioning the dispatcher's update name and the dispatcher's update is getting loaded how how it is happening in the runtime because in the runtime it is loading the class name it is loading it and then instantiating it all by using the reflection technique like this okay and also we'll be able to invoke the methods just like this okay so with this much of knowledge i can come back to the topic that i want to teach today so this is clear right how to invoke a method guys you are okay with this one perfect so this is the prerequisite that i wanted to give so i can close this everything okay now i want to come back to the topic that i want to discuss today so we have 30 more minutes let's complete it okay it's a very simple thing um okay [Music] let's talk about something called dynamic proxy right now so what is a dynamic proxy okay this is this is an interesting thing right now i think we can get some energy and we can understand this particular thing okay it's a similar concept like proxy but it is a dynamic proxy and there is way to create dynamic proxy in java so how can you create dynamic proxy in java okay i'll be telling you there are certain interfaces that you have to you know implement and it is going to help you to create dynamic proxy java has some default features in it there are a couple of types of you know you can create proxy from classes and if you know cg leave from spring or java assist uh these are some you know uh you know api which is gonna help us to create a byte code or proxy from the classes but if you want to create proxy from the interfaces this is something where we'll be talking about the dynamic proxy stuff right so it is a very simple thing and all all your framework is basically using all these things in the low level so you can you can imagine this is your client code and this is your service class which got the business code and from the client code you are making direct call to the business code right so here the call is direct from the client you are making direct call to the service okay but with the dynamic proxy what we will be doing will be implementing this proxy layer as you can see this is a client code this is a business code but the client will call the proxy the proxy will call the business code the proxy will sorry the service will give the response to the proxy and the proxy will give the response to the client code right so the client will not be interacting with the business core directly and we have one more layer as i have told you uh is this one called proxy and here we are going to implement our transaction logging security tracing and blah blah blah right here in this layer and these are going to be our dynamic proxy and our aspect-oriented programming is basically using the dynamic proxy so this is the heart of the concept if you're going to talk about the aspect-oriented programming and if you're going to talk about your spring aop and everything you know the security the annotation that you are saying at transactional like you know um the security annotation that we have discussed inside our spring security course all these things he was just dynamic proxy behind the scene and this basically happens in the low level we are not able to see it and right now we are going to exp like you know experience it and then from tomorrow onwards whenever we're gonna be thinking about dynamic proxy is gonna make so much sense after that okay so now maybe i'm gonna give you some examples of dynamic proxy so let me create a new project uh so java project and i'm gonna say dynamic proxy right do finish i don't want to create any module here okay now imagine i have an interface okay and not class let me say i have an interface okay so let's say i have an interface called let me start it from i let's say i employ and i'm gonna put it inside the package called tto okay so inside the interface called i employee i want to do certain stuff i have some methods for an example i want to give hike to all my in to all my employees so give hike and obviously i'm gonna take the amount that i want to give hike and you know i will return let's say this is returning void and also if some employees are not working if some employees are taking a lot of leaves and if those leaves are not granted i want to do peacock so i will do peacock and in the pay card i will be having also the amount so give me the amount that you want to cut from the employee salary so that i can cut it so i have couple of things called give hike and pay card so evike will will add some amount with the existing salary of an employee pay cut is the method uh if you're gonna give an amount let's say two thousand rupees then it is gonna reduce two thousand rupees from the employee salary okay so let's say we got this interface right now and now we have a method maybe we can create a class and this is going to be my employee class right so this is going to be my employee maybe i can say it this is it employees right and id employee need to implement right now my interface which is i employ okay now it need to override all the methods and i need to give the implementation for this couple of methods and the first thing that i'll be doing here i'll be using private and i will be using um let's say i will be defining some calories a double salary and let's say in the give height i can just do salary is equal to salary plus amount right so whatever the amount someone will give i will accept it and i will add it with this salary right and pay cot i can also deduct the same thing i can just copy the same line and from this salary i can say this dot salary this is also make some more sense this dot salary is equal to salary maybe this dot salary plus amount okay i want to plus the amount whenever someone wants to give hike and i can just do this star salary minus amount if someone want to do a pay cut right and maybe i can just drag some more information about the employee i can just do private and id private string name of the employee maybe i can have some getter and set of methods of this one get to send setup and getters and setters right um this is cool maybe i can also for now for for simply maybe i want to simplify the code a little bit so the people who are just reading it will not be confused i will also take because they might be thinking okay if you have a i employ uh why you don't have this particular methods right there maybe i'm gonna paste this method over here and i'm gonna be defining few more methods in my uh you know i employ even some getters etc just for some easy understanding i will not be using it just defining it over here i'm going to be removing the body of this and just defining the methods over here let's say this is um you know accessories that i have and these are my couple of utility methods which i'll be using to give hike and to do pay cod to an employee okay so this is ready and it employee is also ready now you can just create a client class right you can create a class and let's say this is going to be my client right and my client will have a main method because here i'll be calling the classes that i have created and now let's say i will be creating like you know um id employee object i t employee i t employee id employee is equal to new idea employee okay and now let's say i'll be setting some values here it employee dot set id let's say he got 101 id and it employee dot set name let's say the employee name is available and let's say id employee dot set salary okay we don't have a set salary method so maybe i will just create the getter and set up for the salary maybe i'll also move this at least to get maybe i'll just move couple of methods the accessors to the um it employee i employee interface right now i'm just keeping it uh later i'll be formatting the code i'm just keeping it for understanding so that you can see that whatever the methods that i have over here inside the i employee i got it implemented right here inside the it employee class just for your understanding i kept all my methods inside the interface uh here right and here i got the implementation of everything and now i'll go to my client class and i'll set the salary so set salary and i'm gonna setting the salary let's say his salary is 30 000 okay now i got the id employee object created right now and now i can just do it employee just give give hike let's say i want to give five thousand hike to this particular person and now i can just do sis out and you can just do id employee dot get salary and you will be getting 35 000 as a salary because you have given a hike to this particular employee so it is 80 80 000. what i have done unless you give hike fifty thousand fifty thousand oh sorry basic mathematics and i'm pretty we can method i have told you okay 35 000 here i thought one of what kind of from this logic i have written there okay anyhow this is looking good okay now here comes the twist now i have some requirement and my requirement here is that now i want to do certain things the first thing that i want to do someone can give you hike like this minus 5000 and if someone is giving you a hike like minus 5000 then it will be 25 000 and the high cannot be a negative negative number here and there can be many different conditions from your client from your product owner right who is gonna give you different kinds of requirement this is all my thing that i also want to be get checked before someone gives a hike someone can tell you okay only give a hike if he is a manager only give a hike only if he is it employee but not a you know help desk person or not a attendant or some something else right so we can have different criteria and also let's say i want to log to which employee i'm giving hike or to this employee which method has got called to give a hike i want to do some logging and pressing so where i'll be doing those thing let's say first let's talk about the first condition that i have given you the first condition here is that if i want to give a hike the high cannot be negative number like this and if you want to get it checked where you'll be doing that check will you be doing it over here but if you'll be doing it over here then obviously the code will be bulky the code will be not readable it will be non-rootable code so the ideal thing that we can do here is that we can separate our business code this is my logic that i have written to give the hike and my logic need to be separated from this kind of logging tracing validation checks for this kind of thing and for that instead of making a call directly over here inside the client right here i'm doing it employee.give height we are calling the method called give hike on top of the real object called it employee but i don't want to do that because i want to do it on top of a proxy and how can i do that and here comes the twist and now we are about to create a dynamic proxy in java and the way we'll be creating the dynamic proxy okay uh the way because right now i have given you a few requirements my requirements here is that i want to get it checked if the number is negative i want to have a logger here i want to i want to have i want to see a logo here like the logger like uh okay 5000 hike has been given to the employee of lush i want to get it printed over here to write this logic like to write this kind of work like any pre-processing work or post-processing work along with this work itself i want to create a proxy for that and though and the place where i'll be doing all this thing inside a method called invoke method and that method is given by java okay and you can create it by creating a class here okay and the class name will be let's say uh what is that salary right employee salary employee salary invocation handler right i'll be handling the method invocation here okay and this is going to be a class maybe i'll put it inside the package called proxy okay and inside this package this class need to implement a um a interface and this is the interface given by java and the interface name is invocation handler okay now it got a method the method i want to implement over here and you can see this is the method where i'll be writing my code i will be writing my pre-processing code here i'll be making [Music] actual call to my service layer okay uh like in a business code i can call it over here and i can also do the post processing work here because the proxy we will create out of this handler this is going to be my employee salary invocation handler and using this method will using this class will be creating proxy and every method call that we're gonna make right now on top of our interface which is going to be it employee if you're gonna call pay card if you're gonna call it get id if you're gonna go call give hike if you're gonna make any kind of call on top of this class or on top of this interface i want that call to go by my invocation handler and this is where the entry point will be and don't don't look at that i will be talking about all these things which we have over here like you can see we got a method over here we are just discussing about method let's say someone is calling the give hike method will have a hold of that particular method over here if someone is calling uh get id uh if someone is calling get salary if someone is calling xyz method that method which method is getting called by the client that access i'll be getting over here and let's say someone is calling a method called get salary right here for an example go to this client let's say he's giving minus 5000 minus 50 000 or 5000 itself whatever the argument that he has given for this give height method i will be getting it over here with this arcs there can be multiple arguments that's why this is an array because there can be many arguments for a method so the method name i'll capture over here the method arguments i'll capture over here and also i'll have a capture for my proxy object also here so let's try and try to implement our logic here all right the first thing that i'll be doing inside the employee salary invocation handler i'll be defining my target object so which object i'm targeting guys by the end of this lesson everything will be clear just put your attention i'm gonna do two or three time recap things will be clear i just need five or ten minutes okay put all your concentration here so here first thing that i need i need a target object and my target object here is going to be my uh you know interface name and my interface name here is the employee i employ so copy that go over here and i'll say employ this is going to be my target name i can make it a private control shift or to import this one and now on top of this object i can actually make calls right so the way i can make calls right now i can use this method i can do method dot invoke right and i can pass in the object the object that i will be getting from here but this is an interface okay the where from we'll get the object we will have a constructor right here to initialize it so i'll just give um go to the source go to the constructor using field do it generate and now when someone will create the object of employee salary invocation he'll pass the it employee object or employee impl object any impul object that we have that that will be passed and that will be set to this guy and now here i'll be getting my implementation for an example here i employee do a control t this is the implementation it employ so this object we will get over here right how will be getting it because when someone will create the object of this guy inside the client class let's say some here in the client class someone will come and create the object like this employee salary invocation handler invocation handler that's a pretty big name i'm gonna say emp um salary invoke emp handler is equal to new employee salary invocation handler and now you need to pass the id employee object and you can see this is my concrete object right this is not an interface object this is the impul object now here i'm constructing the employee salary invocation handler object and passing in the it employee object and this got all the values over here now do not call this give height method on top of this let's say i got these three things over here i'm setting all these three things with this it employee i'm setting the id name and salary now inside the invocation handler right here this it employee will be set to this guy using this constructor whenever we'll be using that constructor inside our client code right here because here only we are creating the object okay now let me go to that constructor once the value will be um injected to here i can do method dot invoke and let's say someone is calling a give hike method or someone is calling pecot method someone is calling xyz method those method i want to invoke i want to invoke on top of which object on top of this object called it employee so this is my interface right so it will get this value so i'll copy this target name some people tell it target also maybe i'll say employee target okay so it will it will not it will not be difficult whenever you'll be seeing this one employee target paste it here paste it here okay and paste it here right so now what i can do i can copy this target object and i'll paste it here right and the arguments whatever the argument someone is giving i can simply pass it over here and now i'll be able to call the method so let's try to call the method so now we are actually created a invocation handler and i got a invoke method i know my code flow will come to here whenever i'll make any call on top of my um it employee object or in my employee object so in order to create a proxy for this uh interface and um to to create a proxy i'll be using this handler and the way i'll be doing it inside the client code i will be using a a class called proxy and this is coming from java.lang.reflect and there is a method here called new proxy instance okay it will take three different things the first thing will be the class loader okay i'll be using this class loader which is the implementation of this interface called i employ so i'll go back i'll use this class loader copy this guy go back to the client.java and you can just do it employee dot class dot get class loader okay the next thing will be your interface name like you know what are the interfaces which is implementing this like you know what are the in what are the base interfaces that we have now the best interface that we have for this guy is i employ now i'm going to be copying this guy i'll go back here this is my main interface and i'm going to be placing my interface over here but i will not be able to paste it directly because i need to define it and you can see it is gonna take it as a array of class okay so i'm gonna be creating a new class object new class this is going to be an array and here inside this i'm going to giving my i employee.class this is going to be my second parameter this is going to be the first parameter this is going to be the second parameter and this is going to be the third one and the third one will be basically the invocation handler and my invocation handler is the emp handler so i'm going to be pasting it over here and i'll be wrapping this up so here i'm creating a new proxy object okay and i'm using this invocation handler to create my proxy object now i can just do a ctrl 1 and assign statement to a new local variable and this is gonna give me a proxy object but this is gonna this new proxy instance will return you a object i want i know i'm i'm gonna get my i employee object over here so i can just to cast it to i employ and right here also i can say i employ and i can say um employ here right this is my object proxy object that i'll be getting my employee proxy that i'm creating over here i previously i used to create my proxy object manually right now i'm creating the proxy object by using this like you know method that i have called new proxy instance and using this employee salary invocation handler and this handler i'm passing it to the new proxy instance right here as the third parameter okay and now i'll be getting my proxy now i can just do employee and then i can give any method here i can give employee dot give hike and now this give hike method let's say i'm going to give 5000 rupees height now the method that i'm calling is give hike on top of this proxy called employee now where the flow will go the flow will go to here now here i will be i'll the flow will come to the invoke method and the method here which method i'm calling here look at that the method that i am calling here is give hike so here the method i'll get is give height so i want to invoke the give height method on top of which object on top of this employee target okay and right now this will be initialized why because this object where we're initializing we're initializing that object is here okay we are passing the i t employee here which is a concrete object and we've got all the information so the object will be initialized right here the employee target and now we got the method here right then we'll do method at invoke we're passing the target and also we pass in the arguments the arguments of the method let's say the method that we'll be capturing here will be this one okay give height what is the argument we are passing five thousand that five thousand will be capturing here okay and we are passing all the arguments right here right and this method will be invoked and this will return something and obviously if you if you remember right now the in the employ the the give hike method that we have here this is not returning anything if you're gonna go into that it is a void so it will return null so that's fine if it is going to give something that return type you will be capturing right here in the line number 27 right when you call the method at info now this in block i can return it back or i can just write it result or return type or return value okay and i can just return it over here but right now it is void the method will be void so it will not be returning anything can i go to my client code can i do a right click maybe or after after giving the height i can just do a sis out and i can just do employee which is my proxy object this object copy this and can i got can i can i get the get salary method right now i'm gonna give a sixty thousand hike right now a six thousand hike right now the best price the best salary was thirty thousand let's do right click run is java application let's say we are able to execute the proxy yes and it is giving thirty 36 000 right now now i want to go to the employee salary invocation handler and i'll give a break point here in the line number 27 okay now i'll do a right click maybe i'll do a right click run is java application okay sorry not run yes debug is job application let's see that um how the thing will happen so you know here i'll make a give high call so the call will go to the invocation handler okay let me just come out of this perspective okay and now let's let's see the proxy now the proxy object we got here you can see is the employee salary invocation handler and now it is holding the it employee as a target right and the method that we have here is a give hike method you can see this is my method name give ike and it's accepting a double value right and what is the argument that we have passing in we're passing 6000 to the argument so whatever value we have passed here right on top of this employee proxy we are calling that that method we are capturing here okay and this is the give height method this is the value that we got and this is the proxy object that we got right now we will be invoking this method whenever we'll invoke this now this is going to return value and for now the method has been invoked but right now it is null right obviously um the you know this method is not going to return anything because the type is void as you can see right now if you're going to do a step over let maybe i can do a resume one more time and again you can see the flow is coming to the invoke method of this guy why the flow is coming to here because now look at the method that you have now you have a get salary method you remember i told you any method that you want to call right you are calling on top of what you are you are printing something employee dot get salary again you are doing in the this one previously we are we are seeing now again you are basically calling this method called get salary and you are calling on top of this employee object which is a proxy and this is a proxy and now you are calling the get salary method obviously no nothing is there inside the argument you can go over here and you can do a step above you can say argument should be null method should be get salary and now if you're going to do a step over it is not going i think it is going to return you the value called 36 000 and now if you're gonna do a resume it's printing it over here right so we are basically able to invoke this method on each of our method call that we are making to our original object which is the it employee object actually we are calling to this this object and we are calling the give hike and the pay cut method but the way the call is going through the call is going through through the invocation handler that we have created over here by implementing the invocation handler and as we have the complete access to the method proxy arguments we can do whatever we want as i have told you you want to check whether the height that someone is giving is negative or not maybe you can do it over here you can from the arguments which is a which is the array because we can have many arguments for a method okay you can just call a method you can pass in many arguments now i'm just going to have the first argument because i know i have only one argument so i'm gonna be getting the amount so double okay and i'm gonna say double salary or double hike value okay so this is the value someone is giving right so you can see in the client someone is giving the height of six thousand this six thousand i'm capturing here because the argument will have all the value i'm getting it from the argument and now we can do some checks i can do if now it can do height value is greater is less than or equal to zero 0.0 you're gonna be throwing maybe i can throw an exception directly through new run time exception run time exception and i can pass in the value height amount can't be no can't be a high amount is not valid let me just write like this okay and let's say you want to do some post processing right here you can do the pros processing you can see here i'm doing the pre-processing making the actual call to the real object from to this employee target which will hold the objective it employee and before and after it i'm doing certain things before it i have done certain things and after it i'm going to do some post processing like you know i can have a cis out here and i can say let's say executing method let's say which method i'm executing i'm executing a third on let's say method dot get name let's say this method i'm executing then um for employee id let's say i can just get the employee id let's say from the target so what is that employee target that i have over here from here i will be getting the id or the name whatever you want to print target dot get id right i'm also logging something right here now you can go to the id employee okay and you can just go to the find the java and do right click run is java application and this uh 101 okay but now it is giving me a problem because cannot load from the object array x is no okay now the problem here is that this gets salary is giving me the problem now if you're gonna execute this one this will not give you any problem i'll tell you why we are having the problem java application now it is saying uh it is just saying that give giving hike for the employee id 101 okay and if you're gonna give um you know a negative value here let's say minus six thousand here now this is gonna throw you an exception java exception hike amount is not valid so our validation is triggering but as i have told you whenever you are basically um you know executing the get salary method also for the get salary and now for this method get salary method whenever you are calling this it is also we are also calling it on top of a proxy which is the employee right and now it is giving a null pointed exception it is saying cannot load from the object array x is null why the argument is null we have to make sure guys few things can i go back to um can i go back to my invocation handler now this piece of pre-processing logic that we have written right now it will be executed for each method call that you're gonna make on top of your target method on your target method there are many methods like give hike pay code get id set id so get salary set salary i don't want my preprocessing logic to be executed for every method let's say i only want to be get it done for some certain method so i can make a if clause and i can just wrap my preprocessing logic with the if clause and i'm gonna say only execute this method if method dot get name if the method name equals to what is that what method we are calling can i go back to the client only give hike method copy this go back there and paste it only execute this logic for give hike method and for all the other method pass it out don't cast the argument zero value and don't do certain stuff don't throw me any null pointer exception let me can i do that right now can i do right click run age java application without commenting this line and you can see all the method that i am calling right now give hike it is printing me a log then guess get salary executing the method get salary on the id 101 and also it is just giving me its value called 36 000 and the main point here is that couple of things the way i have built the proxy and the way i have written the employee salary invocation in invocation handler and as as i told you before the spring aop uses this kind of proxy behind the scene okay and the way the transaction management happens is use some invocation handler in a behind the scene okay whatever the method that you want to maintain the transaction for that method undergoes some pre-processing work and some post processing work the pre-processing maybe they will be opening the transaction post processing maybe they will be committing the transaction and in the you know here they're actually making the call to the uh object that you are making uh a transactional annotation annotated with right so this is how the things happens but in the next class we'll be talking about that one so before i wrap up can you guys tell me if these things make sense and oh everyone is over here you guys haven't dropped yet i think you know listen yeah tell me you know if it is making sense and tomorrow will continue yeah it's fine but will it work same if we implement multiple implementation class for the interface exactly it will work same you just need to it you just need to go over here to the job exactly exactly right here you need to keep on adding all your interfaces name some other example i'll be cubing tomorrow so just tell me uh this concept right now making a little bit of sense yes yes okay then just understand guys this is how we will create dynamic proxy and if the other reason why i want to tell you this thing because tomorrow i think while explaining i'll be implementing some invocation handler to show you like you know how the transaction will work behind the scene and you know at that time might be you will be confused if you'll be seeing invocation handler maybe this will work like this will just look like crazy why the heck you are writing in work here what is this method if someone is not aware about reflection he will just he'll just go it'll go away so what is this method what is this proxy what is this class uh object that's why i just wanted to give you a little bit of handstand before we get started for you guys make sure whoever is hearing the recording right now complete this lesson if you are not our about uh the reflection topic and the proxy topic and the dynamic proxy topic make some hands-on then only go to the next class right because as we are progressing with this course i'm planning to give you much more things than the basic thing and that will be done if we'll be you know doing some hands-on like this otherwise you know the things will be complicated if you'll straight away jump into the topic okay any other things guys quickly um ask me my sister is standing uh outside and who wants to she wants to go office anyone has any other um questions quickly ask me i need to go away statement logging statement up here is printing here before that method printing before that yeah of course how is it printing i mean how is it printing okay yes because every time the method is getting called so where is the confusion tell me yeah so every time you called it method that you implemented like the logging statement should be printed before that method after that method yeah after after this thing will be done this statement will be printed for an example okay right now if you follow a different method then if you'll call any different method still the you know you know this logging statement will be called okay all right so just go ahead and just try this one you can go to a client you can you can just copy this guy and just do ctrl b and just do a let's say pay caught uh paychord for this employee let's say i'm gonna be 20 000 i'll reduce right and now let me see it as a target employee target okay going into that okay run is java application and you can see every time i'm calling any kind of method the logging statement will be printed if you want to control it just control it right there okay just control it from here the reason why i'm calling it a target because like this is the object i want to initialize because inside this employee salary invocation handler the way i'll be invoking the method the way i will be invoking the method here method dot invoke right here i'll be invoking upon an object and that is going to be my target object right let's say i want to i want to invoke a method called get salary pay card uh you know uh with let's say any any method like you know give hike any method i'll be executing on top of this guy that's why i'm calling it a target object okay making sense and this object i'm initializing over here right and then i'll be giving initialize it yeah sorry client client client will initialize it yes client will initialize it and maybe there is a better way to do this we can actually move this code um to here as a static method and then client will directly call our static method to uh you know to have the proxy so what you guys can do while practicing you can just move this piece of code to this invocation handler under a just create a method called create proxy and move those code to here okay i will not be doing it guys you know um you know i'll be i'm running out of time so it just move this piece of code to here that you have written and here the client will just call the create proxy method and will pass in certain you know the you know the object called i employ or maybe whatever the things that you want to create and all this invocation handler creation and everything you just hide it with a static method maybe you just create a public static previous calling method employee.give hike will also be shifted here no no employee.hike don't don't shift it over here client will call the business method that's it but he will be calling it through the approximate proxy right yeah client will call it through the proxy method the so here the he will just call the createproxy method that you will design it for me you'll just create the create proxy method okay and on top of this invocation handler maybe um so or maybe get an employee object and using the deploy object you will call from line number correct correct so create proxy method just return you the proxy update so design just move all this code to a create proxy method under this class right here and do that thing for me okay all right thank you okay any other any other question guys quickly if anything else hello upload the code upload the code yes i'll be doing it for my keys please yes yes yes no need to say please [Laughter] actually we should practice you should you should tomorrow guys before you come back please do practice please do practice otherwise uh see this week i'm planning to do hands-on with transaction now so if you are attending five people are attending 10 are attending 15 are attending whoever is attending make sure that you guys are doing hands-on and you guys are okay with the topic and after this week i'll be wrapping up transactional uh annotation stuff okay yeah can we integrate the interceptor here for positive processing and pre-processing interceptor is a different thing interceptor is not proxy supreme right interceptor is the step filter like concept that you have in spring mdc i'm talking about creating dynamic proxy yeah interceptor can do the same work i know you are relating to that because there also we got pre-handle and questionable method right supreme yes but it is for different purposes it is for different purpose correct to like before hitting the controller and correct correct but here we are dealing with proxy okay yeah tell me okay yesterday i wanted to talk to you but you know i had work so maybe i i did not go out and also i thought that i'll be go to play karam and there whenever he'll be calling me i'll be picking your call up but i stuck with the calls and today maybe uh around 1 30 you can ping me here on skype omkar will have a call okay okay all right any other questions any other questions guys no otherwise if i have any other interface apart from imi employees right i should i should again uh write the invocation handler for that and um you need to put it over here and any other interface in this is a interface which implements another interface so here we have ie employee as well you can you can write multiple invocation handler uh labanya okay you can write a multiple invocation handler maybe similar kind of stuff we'll be doing in the next class when we'll be doing with spring aop in the transaction okay okay okay so do you think this prerequisite session makes sense or you guys where most of you are our about all these things no it's really useful sir yes otherwise we couldn't understand the all right okay then maybe i thought that you know most of you should be uh i think the reflection concept you should be knowing about it okay but make sure that you know while you're practicing you're practicing everything because only because i told you about the reflection stop because of this guy only because of this line method method method invoke right just try to invoke some method by using reflection okay cool all right see you guys tomorrow thank you very much bye bye take care recording stopped thank you guys bye have a good day good night bye [Music] all right then so this is it for the session i'll see you guys in the next video with a pretty uh interesting topic because we'll be setting up our spring environment our spring project and we'll get started with the transaction management in spring framework so see you there [Music] you
Info
Channel: Selenium Express
Views: 22,691
Rating: undefined out of 5
Keywords: java proxy, proxy design pattern, proxy design pattern in java, design pattern in java design pattern, spring transaction management, java tutorial, java concepts, dynamic proxy in java, java dynamic proxies api, java programs, learn java, java design pattern, java design patterns and architecture, java dynamic proxy, spring prerequisites, selenium express, abhilash panigrahi, abhilash, abhilash java
Id: EdvMcvNlXfQ
Channel Id: undefined
Length: 92min 6sec (5526 seconds)
Published: Sun Jul 24 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.