I’m trying to understand the difference between the Decorator and Singleton Pattern. For example, in Ruby if I wanted to implement a Singleton Pattern I can use the singleton class. But when I read about the Decorator Pattern in Wikipedia I feel like I would use a singleton class in that case as well.
I’m trying to understand the difference between the Decorator and Singleton Pattern. For example,
Share
The Singleton pattern ensures that only one instance (or a limited number of instances) of a class exists at any given time. On the other hand, the Decorator pattern is a mechanism for dynamically adding functionality (responsibilities) to an object, by changing its “skin”. Singleton is a creational pattern, whereas Decorator is a structural pattern.
There really isn’t much in common between the two of them, what’s the source of your confusion? Wait a bit before using Ruby’s Singleton module, better go straight to the original book and understand the fundamental concepts, before thinking about implementation details.