Search code examples
javadesign-patternsstrategy-pattern

Strategy pattern in javadoc


I am searching Javadoc to identify an implementation of the "strategy pattern" inside Javadoc due to research reasons. I found 2 classes that actually inherited from the FilterInputStream class, the class BufferedInputStream and the DataInputStream. The inherited classes override the read() method of FilterInputStream class. Now according to "strategy pattern" I have to find a method from another class in Javadoc which in its body the read() method is called as well. Can anyone help me, please?.

P.S If you have any other implementation of strategy pattern inside Javadoc in your mind please tell me.

Thanks in advance


Solution

  • Input streams look more as an example of Decorator pattern rather than Strategy.

    Better examples of strategy pattern are uses of ThreadFactory and RejectedExecutionHandler in ThreadPoolExecutor.

    EDIT:

    RejectedExecutionHandler is an interface of a strategy which determines how ThreadPoolExecutor handles rejection of tasks. There are several concrete implementations of such strategires (ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.DiscardPolicy, etc). ThreadPoolExecutor can be configured to use one of them.

    So, it corresponds to this picture (from wikipedia article) in the following way:

    • ThreadPoolExecutor is a Context
    • RejectedExecutionHandler is a Strategy interface
    • ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.DiscardPolicy are concrete strategies (ConcreteStrategyA, ConcreteStrategyB)