October 2018
Intermediate to advanced
370 pages
9h 15m
English
The proxy pattern is useful when we want to restrict or improve a mechanism for accessing an expensive resource. Let's suppose that we want to access a media file. This is an expensive resource and it's better to cache it to avoid multiple loadings. The following diagram shows how this case can be implemented:

The preceding diagram contains the CachedMediaFile class that extends the MediaFile class which, in turn, implements the File interface. Using CachedMediaFile is preferable to MediaFile because it can save memory resources.
The following snippet shows how this pattern works:
interface File { fun showContent()}class MediaFile: ...
Read now
Unlock full access