In a perfect world, we’d want to put this code right into the class of the object, but sometimes that isn’t possible. All of the clients of the object would need to run some setup code and initialize the object. This would probably lead to a lot of code duplication, which is not good. We could use lazy initialization to make an object only when it is needed. We need it sometimes, but not all the time. Why would we want to limit who can use something? As an example, let’s say we have a big object that uses a lot of system resources. You can find the example code of this post on GitHub Conceptualizing the Problem The proxy could connect to anything, like a network link, a big object in memory, or some other resource that is expensive or hard to copy. In its most basic form, a proxy is a class that stands in for something else. A proxy limits access to the original object and lets you do something either before or after the request gets to the original object. The Proxy is a structural design pattern that lets you stand in for another object or act as a substitute.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |