由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Design Pattern Question - Decorator
相关主题
一道design pattern的问题面完fb,结果已经出来了,share下被拒的原因(请转jobhunting版 (转载)
说说Decorator那个题问道FB的题
FaceBook面经--第三(最后)部分amazon第三轮电面
fb面试题【转】Amazon 电面经历
昨天的F家店面讨论:关于一个design 问题
ebay skype interview面经(4轮)amazon的那道题目
FB临门一脚挂了,那种郁闷悔恨的感觉.关于object oriented design的题目
请教一个fb面试问题Amazon 电面
相关话题的讨论汇总
话题: decorator话题: pattern话题: bis
进入JobHunting版参与讨论
1 (共1页)
i**********b
发帖数: 77
1
anyone familiar with Decorator design pattern?
Java I/O is using this pattern. BufferedInputStream and DataInputStream
are all subclasses of FilterInputStream.
they are supposed to work fine when used in any order on an InputStream
This (1):
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
And this (2):
fis = new FileInputStream(file);
dis = new DataInputStream(bis);
bis = new Buffered
Z*****Z
发帖数: 723
2
They both have the same interface for inputting dada. They both need to perf
orm decoration for the input stream. Since they are both subclasses of Filte
rInputStream, they can be chained together. Their neighbor is specified in t
he constructor. So each of them need to get data from the underlying (or nei
ghbor) input stream and do the specific decoration. Then wait the data to be
read by the next neighbor.

anyone familiar with Decorator design pattern?
Java I/O is using this pattern. Buffered

【在 i**********b 的大作中提到】
: anyone familiar with Decorator design pattern?
: Java I/O is using this pattern. BufferedInputStream and DataInputStream
: are all subclasses of FilterInputStream.
: they are supposed to work fine when used in any order on an InputStream
: This (1):
: fis = new FileInputStream(file);
: bis = new BufferedInputStream(fis);
: dis = new DataInputStream(bis);
: And this (2):
: fis = new FileInputStream(file);

J*******n
发帖数: 2901
3
FileInputStream is the component that's being decorated. It gives a base
component
from which to read bytes.
BufferedInputStream is a concrete decorator. It adds behavior / decorates in
two
ways. It buffers input to improve performance, and also augments the
interface
with a new method readLine() for reading character-based input, a line at a
time.
DataInputStream is also a concrete decorator. It adds the ability to let an
application read primitive java data types from an underlying input strea

【在 i**********b 的大作中提到】
: anyone familiar with Decorator design pattern?
: Java I/O is using this pattern. BufferedInputStream and DataInputStream
: are all subclasses of FilterInputStream.
: they are supposed to work fine when used in any order on an InputStream
: This (1):
: fis = new FileInputStream(file);
: bis = new BufferedInputStream(fis);
: dis = new DataInputStream(bis);
: And this (2):
: fis = new FileInputStream(file);

i**********b
发帖数: 77
4
Thank you. Still I don't understand how this can be implemented. I had
understood how it's used though.
A typical Decorator design pattern is implemented using composition. The
Decorator and the Component (to be decorated) shall have the same interfaces
. The decorated component can be treated as an original component.
However, in this case, BufferedInputStream and DataInputStream both added
additional functions to FilterInputStream. If a FilterInputStream is
decorated by BufferedInputStream fir

【在 Z*****Z 的大作中提到】
: They both have the same interface for inputting dada. They both need to perf
: orm decoration for the input stream. Since they are both subclasses of Filte
: rInputStream, they can be chained together. Their neighbor is specified in t
: he constructor. So each of them need to get data from the underlying (or nei
: ghbor) input stream and do the specific decoration. Then wait the data to be
: read by the next neighbor.
:
: anyone familiar with Decorator design pattern?
: Java I/O is using this pattern. Buffered

1 (共1页)
进入JobHunting版参与讨论
相关主题
Amazon 电面昨天的F家店面
弯曲中型IT公司面经ebay skype interview面经(4轮)
老印找工作的确牛FB临门一脚挂了,那种郁闷悔恨的感觉.
MathWorks onsite面经请教一个fb面试问题
一道design pattern的问题面完fb,结果已经出来了,share下被拒的原因(请转jobhunting版 (转载)
说说Decorator那个题问道FB的题
FaceBook面经--第三(最后)部分amazon第三轮电面
fb面试题【转】Amazon 电面经历
相关话题的讨论汇总
话题: decorator话题: pattern话题: bis