Skip to content

Instantly share code, notes, and snippets.

@anjanashankar9
Created February 8, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anjanashankar9/576a894f117518d9866675d1caa51b67 to your computer and use it in GitHub Desktop.
Save anjanashankar9/576a894f117518d9866675d1caa51b67 to your computer and use it in GitHub Desktop.
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