Search code examples
javadesign-patternsdecoratorreentrantlock

Does ReentrantLock use Decorator Design Pattern in java?


ReentrantLock contains an abstract class Sync, and Sync has two subclasses FairSync and NonFairSync. I want to know is this Decorator Design Pattern?

BTW, is there any good resources about Design Pattern usage in java source code?


Solution

  • No it's not. Sync (and FairSync/NonFairSync as well) are only inner classes that are used as an attribute of ReentrantLock (basically, this is only composition, no special pattern involved here).

    The second question will result in opinion-based answers since each person has its own tastes and colors about design patterns (so there is no single good resource about design patterns).

    If you really want to start somewhere, start on Wikipedia where each pattern is explained quite neutrally but in any case it will let you know when (and if) it is appropriate to use them.