Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming patterns - example study

I had this question on my test:

What kind of programming / design pattern is this:

FileReader fr = new FileReader("file.txt");
BufferedReader bf = new BufferedReader(fr);

I'm sorry for the trouble, but definitions of programming patterns are unclear for me and I don't know how to answer this question correctly.

like image 258
Marco Avatar asked Dec 20 '22 22:12

Marco


1 Answers

That's an example of the Decorator Pattern.

As the linked Wikipedia article states:

Decorator pattern is a design pattern that allows behaviour to be added to an existing object dynamically.

In your example, you're adding buffering to a FileReader, which provides more efficient reading than a regular, un-buffered FileReader.

like image 55
Tim Pote Avatar answered Jan 02 '23 04:01

Tim Pote