Hi, Recently i encountered one question about design patterns. The question is can you think of any design pattern which motivated use of comparator. Well i thought for a while then i replied "Decorator Pattern".
My logic behind this answer is that "Decorator Pattern" is used to decorate a single object in different ways by using different decorator still maintaining the object functionality the same.
When we use Comparator we don's change the object but we just change the way they get used for e.g. In Sort i can pass different comparator and can have the method or API show different result but the functionality is same its still sorting just using a different way.
Now the big question is AM I CORRECT?
Please shed some light on your thoughts on my answer.
A Decorator has the same interface as the decorated object, and delegates most of the method calls to the decorated object, while adding behavior to some of them.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus