user20358
user20358

Reputation: 14736

Difference between Proxy pattern and Virtual proxy pattern

I knew of the proxy pattern till now and recently read this article that says a virtual proxy is basically used to defer the Object Creation process of memory-intensive components thereby speeding up the Application.

But after reading that article it looks like the proxy pattern and the virtual proxy pattern are the same thing. Am I right or have I understood this wrong?

Upvotes: 13

Views: 6629

Answers (3)

Tushar Pandey
Tushar Pandey

Reputation: 4857

We can use Virtual Proxy Pattern in case of creating Custom Camera.

Think about if there are 3-4 click option in a page to capture_image, it is not good to create camera object each and every time while we click on capture_image because initializing a surface view ( view used to create camera in android ) takes time. So we can use Virtual Proxy Pattern in this case to use same instance time-to-time and destroy this camera object when the view get destroyed.

Upvotes: 0

taskinoor
taskinoor

Reputation: 46027

There are different types of proxy patterns. Virtual Proxy is one of them. Others (from GOF) are Protection Proxy, Remote Proxy, Smart Reference. From GOF:

A remote proxy provides a local representative for an object in a different address space.

A virtual proxy creates expensive objects on demand.

A protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.

A smart reference is a replacement for a bare pointer that performs additional actions when an object is accessed

Upvotes: 11

Luke Hutteman
Luke Hutteman

Reputation: 1931

The GoF Design Patterns book mentions several kinds of proxies, the virtual proxy (which creates expensive objects on demand) being one of them.

Other types of proxies are remote proxy (which provides a local interface to an object in a different address space), protection proxy (which handles access rights) and smart reference (which performs additional actions when an object is accessed).

So while virtual proxies are definitely proxies, not all proxies are virtual.

Upvotes: 0

Related Questions