Created
November 9, 2014 05:50
-
-
Save sheimi/623563daf2edb081c4ce to your computer and use it in GitHub Desktop.
code in blog.sheimi.me: 2012-06-20-software-architecture-review-4 (3)
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
// Problem | |
abstract class VisualComponent { | |
void draw(); | |
void resize(); | |
} | |
class TextView extends VisualComponent { | |
void draw() {...} | |
void resize() {...} | |
} | |
class StreamVidoView VisualComponent { | |
void draw() {...} | |
void resize() {...} | |
} | |
// Answer | |
abstract class Decorator extends VisualComponent { | |
VisualComponent vc; | |
Decorator(VisualComponent vc) {this.vc = vc;} | |
void draw() {vc.draw();} | |
void resize() {vc.resize();} | |
} | |
abstract class Border extends Decorator { | |
void draw() {super.draw(); drawBorder();} | |
abstract void drawBorder(); | |
} | |
class PlainBorder extends Border { | |
void drawBorder() {...} | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment