Created
January 3, 2018 14:33
-
-
Save darekmydlarz/7e040d2a3dc68f16d814aa1213b9374a to your computer and use it in GitHub Desktop.
Decorator vs Imperative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Image image = new RotatedImage( // just a regular declaration | |
CLOCKWISE, | |
90, | |
new GrayScaledImage( | |
new CachedImage( | |
"//cdn.google.com/logos/apple.png", | |
new RemoteImage("//cdn.google.com/logos/apple.png") | |
) | |
) | |
); | |
return image.bytes(); // all magic happens heere | |
// vs imperative approach | |
ImageService { | |
RemoteImageService remoteImages; | |
ImageCache cache; | |
byte[] getImage(String uri) { | |
Image image = cache.get(uri) | |
if(image != null) { | |
return image; | |
} | |
image = remoteImages.getImage(uri); | |
if(image != null) { | |
return image; | |
} | |
ImageUtils.grayscale(image); | |
ImageUtils.rotate(image, CLOCKWISE, 90); | |
return image; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.