M
M
MaxLich2017-07-18 18:22:32
Java
MaxLich, 2017-07-18 18:22:32

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

Hello. I understand little by little with design patterns, and I can not understand the difference in these patterns. In some places they are considered synonymous. I seem to have found the differences between the adapter and the decorator (as I understand it, the first one implements an interface that is different from the interface of the wrapped object; and the second one implements the same interface as the wrapped object). But I can’t find how the adapter differs from the rapper (wrapper). It is also not clear how a proxy differs from a decorator. PS Code examples (in Java) are desirable to immediately see the differences and similarities.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fat Lorrie, 2017-07-18
@Free_ze

An adapter is a special case of a decorator. Rather, the difference is that a decorator can be larger (contain many entities in itself, while an adapter , as a rule, implements an interface for a specific type).
Proxies are the opposite of the first two, because its task is to be transparent at the junction of type interaction and not change the interface.
Any aggregation can be a wrapper , this is a general concept, roughly the previous types can be called (implemented) wrappers. But more often this means adding some data to the wrapped object. Let's say meta-information.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question