Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
java-decorator-pattern
public void main() {
// FileInputStream - responsible for reading the file
FileInputStream fileInputStream = new FileInputStream("file.txt");
// BufferedInputStream extends FilterInputStream and not FileInputStream, it is
// a decorator which enhances the functionality of the original object by wrapping over it.
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
// The read operation becomes buffered now
bufferedInputStream.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment