November 15, 2005
Experts Exchange Community News
You are receiving this because you are an member who has opted-in to receive newsletters.
What's New at Experts Exchange
The (Dynamic) Proxy Pattern

gregoryyoung is rapidly becoming one of our favorite Page Editors. The original version of this article, including all of the code samples, is located at

A few years ago I was working on a team developing fairly large system. We had purchased a library that provided a lot of useful functionality for our application. We integrated this library very easily, abstracting our object creation using a factory [GoF]. All was wonderful with this component until we came upon scalability issues with it. The data that it returned us was momentarily static; in other words it would rarely change and when it did change, we didn't really care if it took ten minutes for us to get the update, as it was non-critical data. Unfortunately this component would issue a remote call every time it was called, which would take on average between 500ms and 750ms. Low and behold, the vendor had not provided us with a caching mechanism!

The problem was compounded by the fact that we did not have the source code for the program. After a bit of research I happened upon the proxy pattern and in less than 15 minutes solved our problem.

Originally defined in [GoF] the proxy (surrogate) pattern is one of the most under-utilized yet extremely useful patterns available. The proxy pattern is also one of the simplest you will ever use. My personal introduction to the proxy pattern was a typical case of where you will find a proxy in action.

The secret to the proxy pattern's success is the fact that the proxy and the subject meet an identical interface; it is a level of indirection. Due to this they can be used interchangably from the client's perspective. The proxy is returned to the client as if it were the original object and the client need not be concerned on whether it has been returned the original object or the proxy. Due to this, the behavior of a proxy is said to be transparent. The transparency of a proxy is limited to its external contract, though it can significantly alter the behaviors of an object and can cause some limitations.

The proxy pattern is very similar to and often times confused with the adapter pattern by developers new to patterns. The key difference between the adapter pattern and the proxy pattern is that the adapater pattern takes an object and provides a different external contract for it whereas the proxy pattern uses the same contract.

To create a Proxy for this basic class we need to follow a few simple steps.
  1. Inherit from the class we wish to proxy. This will force us to expose the same public contract as the proxied subject.
  2. Create an internal member which will hold our proxied subject.
  3. Override the base's methods to force a call to our proxied subject.
There are many uses for this indirection. The more popular ones include
  • Caching Proxy: The proxy class caches the output of the subject class.
  • Synchronization Proxy: The proxy class forces the thread synchronization of the subject class. This method of providing synchronization is particularly useful since you can have synchronized and non-synchronized versions of your objects causing the non-synchronized to not have the overhead of the synchronization code.
  • Remote Proxy: The object provides a reference to an object living outside of the systems address space via a communications mechanism.
  • Virtual Proxy: Allows "lazy loading" of expensive objects.
  • Firewall Proxy (a.k.a Security Proxy): Allows for the protection of an object.

As you may have realized by now, there are some definite design concerns when working with proxies as there are some objects which are not very conducive to being proxied. Proxies are most conducive to objects which can be presented in their entirety as an abstract contract. Objects which have public variables or have sealed methods are not compatible as the proxy would not be transparent -- the behavior of the subject object would change once the proxy was used. Since objects with purely abstract contracts are the most conducive to the proxy pattern, many people use the proxy pattern with interfaces as opposed to classes.

The process for creating a proxy for an interface is identical to the process for creating a proxy for a class. The nice thing is that since interfaces are by their very definition purely abstract contracts, they are guarenteed to be compatible with the proxy pattern. In fact if you have a class that has a contract which cannot be defined abstractly then you will likely need an interface (or an adapter and an interface if you do not have access to source) in order to make the object compatible with a proxy.

This class could become at least partially proxy compatible if it were to implement the IDoSomething interface, though the proxy would only represent the contract of IDoSomething. Although I would truly love the ability to add exceptions to my object contracts, this is one area where .NET's lack of a strong exception contracting system has actually added to its flexibility. If .NET were to support such a system, the proxy pattern would be affected due to the fact that the proxy could not throw an exception which was not defined by the original object.

Greg Young

Tip from the Moderators: About Community Support

The Community Support topic area is where you communicate with the Moderators. If you want a question deleted or closed, or if you're having an issue with another member, that's your place.

But using it carries some responsibility. If you've asked your question and then abandoned it, and you've gotten a note from a Moderator about it, you'd better make sure you've responded to all of the comments in the question, because the Moderators were Experts before they became Moderators, and they know what it's like to post an answer and not get any feedback from the Asker -- they don't take too kindly to it.

The same is true in Community Support. If you've asked a question, one of the Moderators will respond. Sometimes, the Mod will ask you for more information, or will have a suggestion for you. It's a good idea to respond to them; if you don't, it might have a bearing on whether you get the outcome you want.

It also doesn't hurt to say "Thanks" to the Moderators once in a while. They're all volunteers who have decided to help the site in a manner other than answering questions. They don't earn points for their work, and they do it tirelessly. So a pat on the back to them will be greatly appreciated.

Fake Windows XP service packs

Merete, who has a Guru certificate in Windows XP, received some email and forwarded it to us. It is reprinted, courtesy of the author.

Dear Merete,

I know it has only been 24 hours since my last email but this news is just surfacing on the Internet and could be a timely warning for you.

It seems an "unofficial" Windows XP Service Pack has been made available on the Internet and anyone who installs it on their computers could be in trouble!

Here is one quote from Microsoft I have read:

"Anyone who installs this thinking they are getting SP3 (even as a preview) is being grossly mislead and is posing a significant potentially non-recoverable risk to their PC and data," wrote Mike Brannigan, an enterprise strategy and senior consultant at Microsoft.


...if you come across a link with a suggestion you download the software then AVOID it.

Microsoft has said that its priority is Windows Vista, the next major release of its operating system.

While the company does have plans to release XP SP3, it has not provided details on what the service pack will contain. Microsoft has issued a statement saying that the "content on the unofficial website(s) does not represent Microsoft's plans for Windows XP SP3."

Got a friend who uses Windows XP? Then why not send them a copy of this email...

Kind Regards

Marc Liron
Microsoft MVP
Windows Digital Media

Click here to from the newsletter.
The Premium Services include a number of features not available to "limited" members. Among them:
> Unlimited question points
> VIP Search
> Bookmarks
> Quick Links
> Collapsible menu
> No ads
You can purchase Premium Services on a month-to-month, semi-annual or annual basis, and take full advantage of all that Experts Exchange has to offer!
Page Two: More News and Notes
Nata's Corner: It's about time

woman in specticalsRemember last issue when I mentioned that my new Compaq computer, which came preloaded with Windows XP (and therefore Internet Explorer) has Netscape's home page as the default? I'm glad it is, because there's been some pretty interesting stuff there.

One article that caught my eye was one that talked about how banks are finally upgrading security for the people who use on line banking. My bank offers it, and though my husband swears by it -- I think he's just too laz ... er... busy to balance his checkbook -- I've never tried it. I guess it comes from reading and writing about phishing attacks and such.

Anyway, the article says that while most overseas banks have already incorporated so-called "two-factor authentication", American banks are trying to tweak their web systems, because it's a lot less expensive than handing out SmartCards to all of their customers. It's not that the banks are losing THAT much money; for them, it's just a trade-off in operating expenses. Just wait until the CEO of some bank gets his identity ripped off.

HP and WalMart were in the news last week when a website that watches retail sales posted an item saying that WalMart will start selling HP desktops and laptops for $398 beginning the day after Thanksgiving -- the traditional beginning of the Christmas shopping season. HP sold a $499 laptop (after rebates) earlier this year at the beginning of the back-to-school season, and other companies have sold inexpensive laptops as well, but those usually didn't come with Windows, and they didn't have AMD processors.

Finally, I got a newsletter the other day that says that a "recent poll" -- am I the only one who wonders who does these polls and why doesn't anyone ever say who they are -- showed that 88 per cent of email users don't care if they lose some legitimate email as long as the junk mail gets filtered out. The question the newsletter asked was, "What good is e-mail going to be if you can no longer rely on it?"

I see that as a Hobson's choice. We need email at this point; it can be an efficient and inexpensive communications tool. But the technology brings with it the 100 or so pieces of garbage I wind up deleting every day -- and even though my ISP is kind enough to tag it as junk, a lot of it still gets past their filtering system untagged.

I know the arguments. It's not the ISPs fault, because all they do is send my mail to me OR they're just providing a service to their customers. But I wish I could grab one of those spammers and shove a printed copy of each of their emails... you get the idea.

Inside the numbers
ameba, one of EE's prominent Experts, provides us with a list of newly earned Certificates. His list of all of the Certified Experts is located at his site. The list below covers the period from October 30 through November 13.
Expert Certified in Topic Area
LPurvis boag2000 bluelizard mbizup BejayCole JR2003 mvidas Dabas CSecurity ala_frosty RichardCorrie geotiger jrram angelIII REA_ANDREW pravinasar Ramuncikas dstanley9 lijunguo igor_alpha gregoryyoung chookisa stewartacampbell mgh_mgharish giltjr cooljai1 Sage Guru Guru Master Master Guru Guru Guru Master Master Master Master Guru Master Master Guru Guru Master Master Master Master Master Master Master Master Master MS Access MS Access MS Access MS Access MS Access Visual Basic Visual Basic Visual Basic Visual Basic Microsoft SQL Microsoft SQL Microsoft SQL ASP ASP ASP JavaScript ASP.NET ASP.NET ASP.NET ASP.NET ASP.NET Windows XP Windows XP Windows XP Networking Networking
Expert Certified in Topic Area
mburdick r-k kawas DeanHorak TheLearnedOne Yurich eventprostrategies God_Ares kristinaw eatmeimadanish public FernandoSoto Chaosian KGreg Dimandja TimCottee RobertRFreeman eatmeimadanish marc_nivens bwalker1 fanpages mgh_mgharish XL-Dennis BTognietti nicholassolutions minnirok Master Master Master Master Sage Guru Master Master Wizard Guru Master Wizard Wizard Master Master Master Guru Master Master Master Sage Wizard Guru Master Wizard Master Networking Windows 2000 Java Java C# C# C# C# Exchange_Server Exchange_Server Hardware VB.NET VB.NET VB.NET VB.NET VB.NET .NET Win Server 2003 Win Server 2003 Win Server 2003 Excel Excel Excel Excel PHP PHP
Expert Certified in Topic Area
AndyAinscow OnegaZhang SeanConnolly WillHudson angelIII rpalmeira22 RobWill wasifg sajuks kandura luv2smile blue_zee GrandSchtroumpf Roonaan dij8 sjef_bosman brwwiggins donjohnston nodisco ozo PsiCop kode99 billmercer cjones_mcse ET0000 Sage Master Guru Master Guru Master Master Master Master Sage Master Master Sage Guru Master Sage Master Wizard Master Wizard Sage Master Guru Master Master MFC MFC Outlook MS Office Mysql Applications Applications PHP and Databases PHP and Databases Perl Windows Security Windows Security CSS CSS CSS Lotus Notes/Domino Lotus Notes/Domino Routers Routers Math & Science Netware C++ Builder FileMaker Sharepoint Citrix
1731 experts have 2830 certifications: Genius:69 Sage:128 Wizard:175 Guru:506 Master:1952
Copyright ? 2005. All rights reserved.