What are the differences between Decorator, Wrapper and Adapter patterns?

In theory they are the same, it’s the intent that differentiates one pattern from the other:

Decorator:

Allows objects to be composed/add capabilities by wrapping them with a class with the same interface

Adapter:

Allows you to wrap an object without a known interface implementation
so it adheres to an interface. The point is to “translate” one interface into another.

Wrapper:

Never heard of this as a design pattern, but I suppose it’s just a common name for the above

The example you specify I would categorize as a decorator: The CacheRepository decorates an IRepository to add caching capabilities.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)