Sobes.tech
Junior — Middle

How do the Proxy and Bridge patterns differ in purpose and implementation?

sobes.tech AI

Answer from AI

Proxy and Bridge patterns have different goals and implementation methods:

  • Proxy (Surrogate)

    • Purpose: to control access to another object by adding additional logic (e.g., lazy initialization, caching, access control).
    • Implementation: a proxy object is created that has the same interface as the real object and delegates calls, adding the necessary behavior.
  • Bridge

    • Purpose: to separate abstraction and implementation so that they can be changed independently.
    • Implementation: the abstraction contains a reference to the implementation interface; specific implementations can change without modifying the abstraction.

Example:

  • Proxy is used when access to a resource-intensive object needs to be controlled.
  • Bridge is used when supporting multiple implementation and abstraction variants, such as different platforms or output formats.

Thus, Proxy focuses on access control and additional logic around the object, while Bridge is about separation and independent development of abstraction and implementation.

How do the Proxy and Bridge patterns differ in… - sobes.tech