Thank you :) Don't worry I'll cover that in detail. I have a bunch of refactoring tutorials planned (that is the fancy name for what you're asking for) It is all coming. Sorry it takes so long, but I don't know any other way to do the tutorials the right way
To understand all of this, it is probably best to watch the first 2 parts of my Object Oriented Design tutorial. th-cam.com/video/fJW65Wo7IHI/w-d-xo.html After that I bet everything makes much more sense because I show a real world example from start to finish on how OOP actually works
I should have created code that took full advantage of the pattern, but I came up with this example to keep everything as simple as possible. I'll revisit patterns in the future and try to create better examples.
Thank you so much for these beautiful videos. Financial help provides relief from problems temporarily but education provides relief from all problems forever. you are doing great service. Wish all universities provide free education
Hey, the ATMProxy class constructs a new ATMMachine and returns its field values. How does this help if you need the values of fields from the realATMMachine?
I add comments and sometimes make minor changes if I think it will make the code easier to understand. The videos are normally improved, so if I can help the learning process with a few touch ups I do it. I hope that makes sense
Thank you :) I'm sorry, but I'm not sure what your question is. Feel free to send me a message in TH-cam if you need more space to explain what is confusing. I'll do my best to help
if you use an object of interface type, which is apparantly doing the job of the proxy which is to limit access to methods, what is the use for the proxy object then? great video by the way :-)
You could cast the interface variable to underlying concrete class and get access to all the methods: GetATMData realATMMachine = new ATMMachine(); ((ATMMachine)realATMMachine).getSecret();
you'd render the interface useless then. it is also bad practice. If you need to call a method, in your proxy, it should be part of your contract. if you need to do an authorized call, add a verification of permission step before creating the real object to perform the call on, else perform the call on the proxy, rendering a default result. The role of the proxy is to do pre and post actual operation execution on the real client and provide default implementations if some logic is not met in order to create the real subject for request execution.
@@ForgottenKnight1 I was thinking about the same think. I believe use cases for most of these patterns are not explained correctly. I think the real use case of the proxy is to do post and pre operations. You can access the real class implementation through reflection anyways so proxy is not secure at all.
Hi Derek--- I understand the desire for simplicity. I was expected that proxy would have a composition relationship with the actual ATMMachine and the proxy would only expose the two methods. What are your thoughts?
You are aware that not all the code is available? ATMMachine class has only the new stuff and not any of the stuff from the State Design pattern. And several classes are missing once I fix ATMMachine class. These tutorials are supposed to be self-contained, yes? Besides, that it was a great tutorial. Especially, being able to restrict access to methods of ATMMachine by implementing an GetATMData interface. Pretty elegant.
These videos focus on teaching the patterns. I'm sorry, but the code isn't normally real world ready without some experimenting. I'm looking at patterns further in my refactoring tutorial. I'll be making real world applications with these patterns soon. I hope that makes sense
Hi Derek, Great videos, thanks! I have a question about the Proxy tutorial, i didn't actually understand way in the ATMproxy class you creates a new ATMmachine object inside the methods, It will provides you the same results anytime (for example cash=2000).
In the proxy class methods you use new() comando. Dosen't this just give you an new reference to an new object on an machine. in other words you always get start value of the machine?
***** I was thinking the same. I think he meant to use a private static variable of ATM machine to keep the instance. Or perhaps he meant to update the data in a different way. Either way I agree, it will return only the default values
***** I totally see it the same as you do. It would make sense to keep it in the constructor like Proxy = new ATMProxy(ATMMachine) but wouldn't that be the facade pattern iirc?
+Josh Ii think there is something more to this pattern than what is visible. If you notice he mentions that the proxy creates and destroys objects inside it.
Agree. He's creating two different objects in each getMachineData() and getCash(). Instead, he should reference the same instance variable in both of them. This instance variable ATMMachine is instantiated only then when needed. I would agree that that wasn't representative of the Proxy pattern.
@@kareemjeiroudi1964 He can't do that. How can anyone who is using a Proxy service have access to a real object? If has, he would rather use that. This is not an appropriate example. I found here a better example. Though the process of creating a proxy is correct. th-cam.com/video/TS5i-uPXLs8/w-d-xo.htmlsi=aoo_bS3DISnJvHdd
Hey Derek! Within your ATMProxy class, why do you instantiate a new ATMMachine on every method call? Wouldn't it be more efficient to have it as an instance variable and just access it within each method?
I'm trying to wrap my mind around why creating a proxy will create greater security? Is there maybe an eli5 to answer this? My best guess is if someone hacks into a proxy and starts poking around, if they don't realize it's a proxy then they'll just figure the data that's within the proxy isn't important or useful enough to work with and so will move on to another target?
It is good to follow good coding practice. When you define interface name , it should be preceded by letter 'I' that would help to differentiate an interface from a class. Anyway , I want to thank you for the knowledge sharing. and i clicked on the like button too :)
Hey Derek, Appreciate your efforts and thanks for making such informative and easy to understand video! I have a comment, I think that this example is not utilizing the proxy pattern correctly. When we create the object using the Interface, it can utilize the behavior of that interface only. If there is any behavioral change happening in the proxy class which provides the original class a kind of security for example, then it makes sense to use the proxy class. Correct me, if I'm wrong!(P.S. This is new to me.)
I've just watched this video and I noticed that as well. His implementation is not right. He should have added a second part to this video where the state of the ATM machine is altered (by some person) and the proxy still works as expected. He would have then made the right changes to his code.
Hi, Derek. Great tutorials and thanks so much for doing them. I'm working through the playlist. A request if you think it would be worthwhile: a comparison of when you would use one design pattern vs. another? I understand for example that, conceptually, the Bridge is structural and the Strategy pattern is behavioral, but how do we really think through that in a real world example? (I think I understand when you would use each of those, but I'm using those as an example.) Thanks!
So wait i dont get it, in order to create atm proxy we basically need to create real atm machine (inside the proxy) now for that to happen it means the code needs to KNOW real atm class to begin with. so if we can create atm proxy instance, we can create real atm machine instance in whatever code we work, then we would simply access whatever we want from the real atm and simply ignore the proxy... how is this really limiting someone? what forces someone to work only with the proxy? what prevents them from just creating real atm machine instance and using that, so what is exactly limiting this "outside program" from doing just that?
I think this is more a type of "Protection Proxy"? It is important to point out that we have different type of proxy implementation : Remote Proxy, Virtual Proxy, Copy-onWrite Proxy , Protection Proxy , Cache Proxy , firewall Proxy , Synchronization Proxy , Smart Reference Proxy.
Derek Thank you for this service you have provided by giving detailed implementations for these design patterns. Need some help with this one pattern. The realATMMAchine that is created in the TestATMMAchine is not used inside the ATMProxy? Instead ATMProxy uses its own newly generated copy. How do I reconsile this?
If anyone is having problems with this, when you create the project, use all the java files from the State Design Pattern as a base to work with. The Code in the link above doesn't all the files you will need.
Hello, Derek! I have some kind of request for you: can you show how to implement proxy for remote access? For example client-server. May be remote weather station on one side and client that can get temperature remotely via network on another.
I have a question. I understand that you created an interface (GetATMData) and you created the concrete classes (ATMMachine and ATMProxy) for that interface so why don't you use ATMMachine rather than ATMProxy. ATMMachine is still restricted by the interface when instantiated by the object realMachine. Example: you could do realMachine.getATMState() or atmProxy.geATMState().
Nice, but 2 questions Derek: - In the ATMProxy.java file is it a good idea to use a private field with ATMMachine and not creating it over and over again? - If you can access the "non-secret" methods only from the realATMMachine object, why make the proxy? Isn't the interface the proxy itself?
Hi, thanks a lot for this awesome tutorial. Can you please explain to me how do I make ATMMachine unaccessible? because I understand that right now it is accessible just as much as ATMproxy.
***** Yes I agree, but I felt that making an understandable tutorial would be useful. Then with that knowledge they could move on to the GOF book for more complex examples.
It is perfectly understandable, ie - the example is perfectly understandable, but how is this used or what is the benefit of using proxy is now completely lost on me... yes i understand the example, not the design pattern :\
I am in the internet, and i am diving into examples, its how i ended up on this video to begin with, i merely criticized this example i came across, no one assumes a person wont understand and stop dead in his tracks, of course i looked for other examples as well.
Hi Derek I hope this is not a bad question to ask. I was wondering what is the point of making the realAtMachine when you have already created methods to get information from the ATMMachine class within the proxy. It can work without the realAtMachine right?
Anirudh Upadhyayula There are no bad questions. Yes you could do what you said. In trying to make the pattern easy to understand I some times don't use the pattern to its full capabilities. Often to show what makes the pattern great would require a very complex example.
Hi! Thanks a lot for your patterns videos, we don't get to learn those thing in my programmer formation... :) I was playing with your classes from that exemple and I'm wondering why we need the proxy class when we can just use an ATMMachine like that: GetATMDataManager ATMMachine = new ATMMachine(); ?
You're very welcome :) To try and keep everything understandable I choose to keep the example simple even if it didn't necessarily require a pattern to optimize the code. Sorry if that was confusing.
I have a Maven multi-module project with three layers: (3) The Main class that depends upon (2) The middle layer which depends on (1) The API layer (utilities, etc). Normally, the middle layer cannot access the Main class (because you can't have circular dependencies)... In order to get around this, I had the Main class implement an interface declared in the first api layer. Would this be an example of a Proxy ? Or another design pattern ? Or did I just hack it together and it's not even a design pattern at all ? Thanks!
I'm getting into these design patterns way too late. I hope my ramblings make some sense. If the purpose of the proxy is, in this case, for security then clearly it should not be possible for the same client to create an instance of ATMMachine. Now if ATMMachine implements the interface GetATMData surely that is enough, you don't add anything with the proxy class. I suppose a more useful real world implementation would be a web service that uses authorisation and implements the methods ATMMachine and another web service that does not require authorisation that implements GetATMData. However this being the case I'd also not quite see the purpose of the proxy pattern in this case. I suppose actually what this example would benefit from would be if it combined one of the builder patterns. Perhaps a Factory would be used to prevent clients creating instances of the ATMMachine. The Factory could then use some kind of authorisation (being a .Net guy myself that should the straightforward and I'm sure Java has something similar) and allow certain clients to create ATMMachine while everyone can create GetATMData. However even then this would not be a proxy.
+Nick Askew At first I also agreed with the fact that the proxy class actually doesn't add anything, and actually made this video a bit confusing for me at first... but after thinking a bit, the proxy class could definitely add something, because the GetATMData realAtmMachine = new ATMMachine() could be casted to (ATMMachine) realAtmMachine, which would nullify the prevention of the usage of the setters and such. Of course, I'm not entirely sure, but I think that that is the only logical way why the proxy class would be placed there. but all in all it's hard to say, there's not enough depth in this kind of code to see a real good use of it I guess.
If I have two different classes that use the same interface and I want to secure both with my Proxy-Class, do I need in this case two Proxy-Classes or is one enogh for both?
Hi Derek, Can you please explain what is the right way of passing the original obejct to the proxy object? In the video it is not clear . snag.gy/biaUoG.jpg . Instead of passing the instance of real object , you are just creating a new object in every call to your proxy methods .
Hello Derek Banas, Thank you first for the great toturial. I have a question about the main idea behind the proxy design pattern. Let M be a set of methods defined in the protected class ATMMachine, and S is a subset of M, with for each element m in S, m should not be accessible outside of the class ATMMachine(S ist the set of secure methods). In this case we can declare the elements of S as private and M \ S (The set of methods that are accessible outside of the ATMMachine) as public. This implies that the secure methods a not visible outside of the class ATMMachine. Does this approach has any limits that we must use the proxy design pattern. If this is the case, then why? Thank you in advance! Ayoub
Is Data abstraction and proxy design pattern same? why because data abstraction also limits the functionality of a class to an interface object. then what is the main difference?
Because realATMMachine reference is of type GetATMData. You can only use methods and fields that are in this interface. If realATMMachine's type is ATMMachine then you can access all visible methods and fields.
hi, great videos! thank you very much. i have a question, in this tutorial you are assuming that all instances of ATM Machine are the same because when you ask the proxy to give you some data it creates a new ATM Machine instance. in a normal situation, every instance will have its own characteristics ( the constructor will not be empty), so then what you do? I may have an ATM machine that have been modified and changed since it was constructor, making new one will not give me what I want.
Hey Coach , did you cover live() , bind() , delegate() in Jquery and closures in Javascript by any chance. If yes please share the exact link. Thanks for all the self less help.
Hmmm, shouldn't the proxy should be controlling access to a real object, instead of creating a new object everytime? This example is like the bank buying a new ATM machine everytime a branch manager tries to check balance.
Hi! Explain me if U could. I´m kinda new in Patterns. It´s not real world ok, but if that was the case, I wouldn´t just create new ATMMarchines about every method of the interface right? It would get me nowhere, givin me values of forever new objects. Normally it´s used alongside Factory Pattern, for example? Can U give me a real world example? Note.: Added you on G+, nice to meet u and congratulations!
can u create proxy (ip) changer soft. that can automatically change the proxy "IP"in given time dynamically and also create proxy chains.. :) plz.... at least algorithm i cant think how to create this .
ATMMachine class is public and the methods which are defined in the interface are also public. So how does it prevent an attacker from using ATMMachine instead of the proxy?
Attacker? Code is compiled into a program. Attackers do not write the code. All these are meant for developers to write a code that cannot be misused by other developers, can be shared, extended, tested, etc.
2024 and still one of the best tutorial for design patterns.
I will have an exam this week and I have to know a lot of design Patterns, and your tutorials helped me a lot. Great tutorials. Thanks.
almost 10 years later and these are still great!
Thank you very much :)
I'm just very happy that you like them. This stuff translates perfectly into C# I'm sure. I'm glad you have benefited with you VB coding as well :)
Thank you :) Don't worry I'll cover that in detail. I have a bunch of refactoring tutorials planned (that is the fancy name for what you're asking for) It is all coming. Sorry it takes so long, but I don't know any other way to do the tutorials the right way
These videos are timeless. Thank you for putting them up.
Thank you for the great compliment :) Happy I could help
To understand all of this, it is probably best to watch the first 2 parts of my Object Oriented Design tutorial. th-cam.com/video/fJW65Wo7IHI/w-d-xo.html
After that I bet everything makes much more sense because I show a real world example from start to finish on how OOP actually works
I should have created code that took full advantage of the pattern, but I came up with this example to keep everything as simple as possible. I'll revisit patterns in the future and try to create better examples.
Thank you so much for these beautiful videos. Financial help provides relief from problems temporarily but education provides relief from all problems forever. you are doing great service. Wish all universities provide free education
Hello, I definitely have tutorials on networking planned and I'll get to them ASAP
Hey, the ATMProxy class constructs a new ATMMachine and returns its field values. How does this help if you need the values of fields from the realATMMachine?
it doesn't, this is an awful example
oh god... thanks Jesse, i was banging my head feeling like i am a fucking moron for not seeing how it helps at all....
@@beepIL Even I was a bit confused and realised that's the problem with academic tutorials. I am searching for the real world example.😂😂😂
Thank you :) I'm going to cover hibernate and spring very soon. Thank you for the request
easiest to understand explanation on the interwebs. :) Thank you!
You're welcome :) Glad I could help
I add comments and sometimes make minor changes if I think it will make the code easier to understand. The videos are normally improved, so if I can help the learning process with a few touch ups I do it. I hope that makes sense
Eres rápido! No hay de qué. Tenga un fin de semana bendecido, así
You're the man SawMan :)
Thank you :) I'm sorry, but I'm not sure what your question is. Feel free to send me a message in TH-cam if you need more space to explain what is confusing. I'll do my best to help
You're very welcome :) Im glad they helped
if you use an object of interface type, which is apparantly doing the job of the proxy which is to limit access to methods, what is the use for the proxy object then?
great video by the way :-)
You could cast the interface variable to underlying concrete class and get access to all the methods:
GetATMData realATMMachine = new ATMMachine();
((ATMMachine)realATMMachine).getSecret();
you'd render the interface useless then. it is also bad practice. If you need to call a method, in your proxy, it should be part of your contract. if you need to do an authorized call, add a verification of permission step before creating the real object to perform the call on, else perform the call on the proxy, rendering a default result. The role of the proxy is to do pre and post actual operation execution on the real client and provide default implementations if some logic is not met in order to create the real subject for request execution.
@@ForgottenKnight1 I was thinking about the same think. I believe use cases for most of these patterns are not explained correctly. I think the real use case of the proxy is to do post and pre operations. You can access the real class implementation through reflection anyways so proxy is not secure at all.
Awesome Derek.. :).. Best part in the presentation is its clear, crisp and to the point.. and most importantly touching right cells in my brain :)
Hi Derek--- I understand the desire for simplicity. I was expected that proxy would have a composition relationship with the actual ATMMachine and the proxy would only expose the two methods. What are your thoughts?
You are aware that not all the code is available? ATMMachine class has only the new stuff and not any of the stuff from the State Design pattern. And several classes are missing once I fix ATMMachine class. These tutorials are supposed to be self-contained, yes? Besides, that it was a great tutorial. Especially, being able to restrict access to methods of ATMMachine by implementing an GetATMData interface. Pretty elegant.
I used bind a lot in part 3 of my JQuery tutorial and others after it. I didn't cover live or delegate though
These videos focus on teaching the patterns. I'm sorry, but the code isn't normally real world ready without some experimenting. I'm looking at patterns further in my refactoring tutorial. I'll be making real world applications with these patterns soon. I hope that makes sense
Hi Derek, Great videos, thanks!
I have a question about the Proxy tutorial, i didn't actually understand
way in the ATMproxy class you creates a new ATMmachine object inside the methods,
It will provides you the same results anytime (for example cash=2000).
In the proxy class methods you use new() comando. Dosen't this just give you an new reference to an new object on an machine. in other words you always get start value of the machine?
***** I was thinking the same. I think he meant to use a private static variable of ATM machine to keep the instance. Or perhaps he meant to update the data in a different way. Either way I agree, it will return only the default values
***** I totally see it the same as you do. It would make sense to keep it in the constructor like Proxy = new ATMProxy(ATMMachine) but wouldn't that be the facade pattern iirc?
+Josh Ii think there is something more to this pattern than what is visible. If you notice he mentions that the proxy creates and destroys objects inside it.
Agree. He's creating two different objects in each getMachineData() and getCash(). Instead, he should reference the same instance variable in both of them. This instance variable ATMMachine is instantiated only then when needed. I would agree that that wasn't representative of the Proxy pattern.
@@kareemjeiroudi1964 He can't do that. How can anyone who is using a Proxy service have access to a real object? If has, he would rather use that. This is not an appropriate example. I found here a better example. Though the process of creating a proxy is correct. th-cam.com/video/TS5i-uPXLs8/w-d-xo.htmlsi=aoo_bS3DISnJvHdd
Hey Derek! Within your ATMProxy class, why do you instantiate a new ATMMachine on every method call? Wouldn't it be more efficient to have it as an instance variable and just access it within each method?
Very nice explanation of proxy pattern that how to show and hide information of real system from remote requests.
Thank you :)
Thanks for posting this Derek. Simple and clear.
You are very welcome :)
Está muito bem-vindos :)
I love your videos, explained short and clearly!
Keep this Derek :)
Thank you :)
You're very welcome :)
Derek, thank you for this simple tutorial.
I'm trying to wrap my mind around why creating a proxy will create greater security? Is there maybe an eli5 to answer this? My best guess is if someone hacks into a proxy and starts poking around, if they don't realize it's a proxy then they'll just figure the data that's within the proxy isn't important or useful enough to work with and so will move on to another target?
It is good to follow good coding practice.
When you define interface name , it should be preceded by letter 'I' that would help to differentiate an interface from a class.
Anyway , I want to thank you for the knowledge sharing.
and i clicked on the like button too :)
Hey Derek, Appreciate your efforts and thanks for making such informative and easy to understand video!
I have a comment, I think that this example is not utilizing the proxy pattern correctly. When we create the object using the Interface, it can utilize the behavior of that interface only. If there is any behavioral change happening in the proxy class which provides the original class a kind of security for example, then it makes sense to use the proxy class. Correct me, if I'm wrong!(P.S. This is new to me.)
I've just watched this video and I noticed that as well. His implementation is not right. He should have added a second part to this video where the state of the ATM machine is altered (by some person) and the proxy still works as expected. He would have then made the right changes to his code.
Hi, Derek. Great tutorials and thanks so much for doing them. I'm working through the playlist. A request if you think it would be worthwhile: a comparison of when you would use one design pattern vs. another? I understand for example that, conceptually, the Bridge is structural and the Strategy pattern is behavioral, but how do we really think through that in a real world example? (I think I understand when you would use each of those, but I'm using those as an example.) Thanks!
So wait i dont get it,
in order to create atm proxy we basically need to create real atm machine (inside the proxy)
now for that to happen it means the code needs to KNOW real atm class to begin with.
so if we can create atm proxy instance, we can create real atm machine instance in whatever code we work,
then we would simply access whatever we want from the real atm and simply ignore the proxy...
how is this really limiting someone? what forces someone to work only with the proxy? what prevents them from just creating real atm machine instance and using that, so what is exactly limiting this "outside program" from doing just that?
I think this is more a type of "Protection Proxy"? It is important to point out that we have different type of proxy implementation : Remote Proxy, Virtual Proxy, Copy-onWrite Proxy , Protection Proxy , Cache Proxy , firewall Proxy , Synchronization Proxy , Smart Reference Proxy.
Derek Thank you for this service you have provided by giving detailed implementations for these design patterns. Need some help with this one pattern. The realATMMAchine that is created in the TestATMMAchine is not used inside the ATMProxy? Instead ATMProxy uses its own newly generated copy. How do I reconsile this?
If anyone is having problems with this, when you create the project, use all the java files from the State Design Pattern as a base to work with. The Code in the link above doesn't all the files you will need.
Hello, Derek! I have some kind of request for you: can you show how to implement proxy for remote access? For example client-server. May be remote weather station on one side and client that can get temperature remotely via network on another.
I have a question. I understand that you created an interface (GetATMData) and you created the concrete classes (ATMMachine and ATMProxy) for that interface so why don't you use ATMMachine rather than ATMProxy. ATMMachine is still restricted by the interface when instantiated by the object realMachine. Example: you could do realMachine.getATMState() or atmProxy.geATMState().
Automatic Teller Machine Machine
Great work Derek!
+Filip Ghimpeteanu Thank you :)
Nice, but 2 questions Derek:
- In the ATMProxy.java file is it a good idea to use a private field with ATMMachine and not creating it over and over again?
- If you can access the "non-secret" methods only from the realATMMachine object, why make the proxy? Isn't the interface the proxy itself?
Hi, thanks a lot for this awesome tutorial.
Can you please explain to me how do I make ATMMachine unaccessible?
because I understand that right now it is accessible just as much as ATMproxy.
Thanks Derek! Amazing tutorials. Thanks for all the efforts :)
Thank you :) I'm happy to help
I do my best :)
In wich way could I protect one class with a proxy, if that class could be instantiated directy?
The problem with giving so simple examples is that no one actually sees the benefit of using Proxy.
***** Yes I agree, but I felt that making an understandable tutorial would be useful. Then with that knowledge they could move on to the GOF book for more complex examples.
It is perfectly understandable, ie - the example is perfectly understandable, but how is this used or what is the benefit of using proxy is now completely lost on me...
yes i understand the example, not the design pattern :\
There's plenty of resources in the internet to dive deeper. I believe Derek is just trying to give us a clear introduction to the design pattern.
I am in the internet, and i am diving into examples, its how i ended up on this video to begin with, i merely criticized this example i came across, no one assumes a person wont understand and stop dead in his tracks, of course i looked for other examples as well.
Well, I am a bit confused.
If you don't want others to have access to setATMData(), why don't you just make it a private function?
Thank you! It's an amazing tutorial!
+João Neves Your welcome :) Thank you
Nice video as usual. Derek, can you do a Java - Hibernate Annotations tutorial? I wanna learn but I'm kinda stucked. Thanks!
Hi Derek I hope this is not a bad question to ask. I was wondering what is the point of making the realAtMachine when you have already created methods to get information from the ATMMachine class within the proxy. It can work without the realAtMachine right?
Anirudh Upadhyayula There are no bad questions. Yes you could do what you said. In trying to make the pattern easy to understand I some times don't use the pattern to its full capabilities. Often to show what makes the pattern great would require a very complex example.
"Adawise till next time" ; nice statement to end a video !
Hi! Thanks a lot for your patterns videos, we don't get to learn those thing in my programmer formation... :)
I was playing with your classes from that exemple and I'm wondering why we need the proxy class when we can just use an ATMMachine like that: GetATMDataManager ATMMachine = new ATMMachine(); ?
You're very welcome :) To try and keep everything understandable I choose to keep the example simple even if it didn't necessarily require a pattern to optimize the code. Sorry if that was confusing.
It's not confusing at all, I've never been so enlightened since I started my programing clases :)
Steve Boisvert Thank you :) I'm very happy that I could help. My refactoring tutorial should be very interesting if you have found these useful.
Wow! This is a great tutorial
Thank you :)
I have a Maven multi-module project with three layers: (3) The Main class that depends upon (2) The middle layer which depends on (1) The API layer (utilities, etc).
Normally, the middle layer cannot access the Main class (because you can't have circular dependencies)... In order to get around this, I had the Main class implement an interface declared in the first api layer.
Would this be an example of a Proxy ? Or another design pattern ? Or did I just hack it together and it's not even a design pattern at all ? Thanks!
I'm getting into these design patterns way too late. I hope my ramblings make some sense.
If the purpose of the proxy is, in this case, for security then clearly it should not be possible for the same client to create an instance of ATMMachine. Now if ATMMachine implements the interface GetATMData surely that is enough, you don't add anything with the proxy class.
I suppose a more useful real world implementation would be a web service that uses authorisation and implements the methods ATMMachine and another web service that does not require authorisation that implements GetATMData. However this being the case I'd also not quite see the purpose of the proxy pattern in this case.
I suppose actually what this example would benefit from would be if it combined one of the builder patterns. Perhaps a Factory would be used to prevent clients creating instances of the ATMMachine. The Factory could then use some kind of authorisation (being a .Net guy myself that should the straightforward and I'm sure Java has something similar) and allow certain clients to create ATMMachine while everyone can create GetATMData. However even then this would not be a proxy.
+Nick Askew At first I also agreed with the fact that the proxy class actually doesn't add anything, and actually made this video a bit confusing for me at first... but after thinking a bit, the proxy class could definitely add something, because the GetATMData realAtmMachine = new ATMMachine() could be casted to (ATMMachine) realAtmMachine, which would nullify the prevention of the usage of the setters and such.
Of course, I'm not entirely sure, but I think that that is the only logical way why the proxy class would be placed there. but all in all it's hard to say, there's not enough depth in this kind of code to see a real good use of it I guess.
If I have two different classes that use the same interface and I want to secure both with my Proxy-Class, do I need in this case two Proxy-Classes or is one enogh for both?
Hi Derek,
Can you please explain what is the right way of passing the original obejct to the proxy object? In the video it is not clear . snag.gy/biaUoG.jpg . Instead of passing the instance of real object , you are just creating a new object in every call to your proxy methods .
I notice the same, i think you must use composition geting the instace through the constructor
Have been following your videos. But this one is confusing since it creates a new instance of real machine every time. Is this correct ?
Hey Derek, can you recommend a book that teaches java programming well and is very easy to understand?
Head First Java is very good
Derek Banas thank you for replying. Do you know any books for C++ as well?
Styles P'yall C++ Primer Plus
Thank you!
Hello Derek Banas,
Thank you first for the great toturial. I have a question about the main idea behind the proxy design pattern. Let M be a set of methods defined in the protected class ATMMachine, and S is a subset of M, with for each element m in S, m should not be accessible outside of the class ATMMachine(S ist the set of secure methods). In this case we can declare the elements of S as private and M \ S (The set of methods that are accessible outside of the ATMMachine) as public. This implies that the secure methods a not visible outside of the class ATMMachine. Does this approach has any limits that we must use the proxy design pattern. If this is the case, then why?
Thank you in advance!
Ayoub
I was thinking about the same think. I believe use cases for most of these patterns are not explained correctly.
Show the ATMMachine class properly in the code link given it's Missng few lines of Code.
Why did you make AtmMachine implement the interface as well ?
Could you not do a dynamic cast from GetATMData on the real machine to ATMMachine?
Is Data abstraction and proxy design pattern same? why because data abstraction also limits the functionality of a class to an interface object. then what is the main difference?
Hi Derek, I could not understand why "realATMMachine" cannot access the "secret" variables either. Thanks.
Because realATMMachine reference is of type GetATMData. You can only use methods and fields that are in this interface. If realATMMachine's type is ATMMachine then you can access all visible methods and fields.
hi, great videos! thank you very much. i have a question, in this tutorial you are assuming that all instances of ATM Machine are the same because when you ask the proxy to give you some data it creates a new ATM Machine instance. in a normal situation, every instance will have its own characteristics ( the constructor will not be empty), so then what you do? I may have an ATM machine that have been modified and changed since it was constructor, making new one will not give me what I want.
Hey Coach , did you cover live() , bind() , delegate() in Jquery and closures in Javascript by any chance.
If yes please share the exact link.
Thanks for all the self less help.
yes it does, thank you very much, i will get to refactoring soon enough :) and thanks for the quick reply!!
You talked how it hide set cash method but you never showed which class exactly had this method.
Hmmm, shouldn't the proxy should be controlling access to a real object, instead of creating a new object everytime? This example is like the bank buying a new ATM machine everytime a branch manager tries to check balance.
I don't like the new object creation also, I'm not sure it's correct, you always get the default values this way.
Hi! Explain me if U could. I´m kinda new in Patterns. It´s not real world ok, but if that was the case, I wouldn´t just create new ATMMarchines about every method of the interface right? It would get me nowhere, givin me values of forever new objects. Normally it´s used alongside Factory Pattern, for example? Can U give me a real world example?
Note.: Added you on G+, nice to meet u and congratulations!
love the proxy pattern
bhai this is the best pattern
You can't access the set methods because there are none?
can u create proxy (ip) changer soft. that can automatically change the proxy "IP"in given time dynamically and also create proxy chains.. :) plz.... at least algorithm i cant think how to create this .
Hi, the code is not the same as what you have shown in the tutorial?
ATMMachine class is public and the methods which are defined in the interface are also public. So how does it prevent an attacker from using ATMMachine instead of the proxy?
Attacker? Code is compiled into a program. Attackers do not write the code. All these are meant for developers to write a code that cannot be misused by other developers, can be shared, extended, tested, etc.
proxy instantiates real object? oh, that's funny
yeah, why?
If you notice he mentions that the proxy creates and destroys lot of objects inside it.
Very nice
Gracias por su ayuda. Tenga un fin de semana bendecido.
Fastet Finger First .....sixth "GOLD" :)
is proxy and dynamic proxy same?
why can't we use Abstract class instead of Interface ?
You could, but it is considered best to not use them unless you must have a non-abstract method
Many Thanks!
I'm happy to help :)
Thanks! Obrigado!
"Expensive" not "intensive" :d
Second place !
HI
Hi :)