[ComponentDesignPatterns | CategoryPattern] '''Context''' ''Applicability'' '''Problem''' '''Forces''' * '''Solution''' ''Participants'' ''Structure'' ''Collaborations'' '''Resulting Context''' ''Consequences'' '''Known Uses''' '''Example''' ''Implementation'' ''Sample Code'' '''Related Patterns''' ---- [''Old pattern format used originally below; currently metamorphosizing to standard format. -ed''] '''Intent''' Build a layer of translation objects (Adapters and Facades) to act as intermediaries when crossing component space boundaries. '''Motivation''' In many large projects you end up with several distinct component "spaces", each with their own languages, protocols and quirks. You have to be able to handle the transition between each space properly to make the final system work. This is analogous to "going through customs" to get from one country to another. For instance, one large-scale system that I've worked with used CORBA as its inter-process communication mechanism between several "core" processes, and then used RMI or Sockets for communication from the core server processes to the clients. At each transition point we had to adapt from one set of assumptions to another. For instance: (1) When going from Java to CORBA to Java we had to take our internal Java domain objects and "flatten" them into CORBA structures to send to the other processes since CORBA does not allow pass-by-value. We could have used Java serialization, but the major reason we chose CORBA was due to the possibility that we might code some of our core processes in other languages (e.g. C++). (2) Often the same service needed to be offered in two or more protocols. For instance, we had a few components (usually application facades) where their services needed to be provided simultaneously in CORBA and RMI. Here we would sometimes build a "translator" object (an Adapter) whose job it was to speak a particular protocol and have two of these pass through to the actual underlying component. The key here is using the metaphor to understand what you need to do. Laws differ between countries -- you can bring things into one country that you can't bring in to another. Likewise, protocols differ -- RMI gives you pass-by-value, where CORBA doesn't. CORBA and RMI are method-call oriented, while Sockets are connection oriented. Translation (Adapter and Facade) objects are usually needed to act as "customs agents" to make sure the laws of each component space are enforced. ----- Nice metaphor. It reminds me that going through customs (in some countries from some countries, in particular) is *painful (and slow). --AlistairCockburn ---- Usually when you go from one country to another, you are required to bring credentials that allow them to certify who you are. For example, a passport is frequently used when going from one country to another. If you sneak in, or if you give them false identification, they can kick you out and never let you back in. --PhilipEskelin ----- It is interesting, if slightly off the point, that correspondance between highly ranked officials which is personal point-to-point on a topic of public or general interest is often called "Back Door" Communication or "Private Channel" or "Diplomatic Pouch" etc. -- and is intended to evade customs so to speak. In software we designate inadvertant points of entry or seizure of control as "back doors" -- all of this undoubtedly has something to do with the way our brains are wired up. --RaySchneider And they have special visas for rock stars, executives from global corporations, etc. --PhilipEskelin ----- How does this relate to ComponentGlue? --NatPryce ----- Good question. In my opinion a lot of ComponentGlue in systems is a direct result of GoingThroughCustoms. There are other reasons, of course, but a lot of glue code (conversions, changing formats, etc.) results from customs. KyleBrown ----- GoingThroughCustoms and ComponentGlue are highly compatible. ComponentGlue can act in the role of an adapter, and even act as a mediator. Depending on whether you are assembling and integrating components or layering your solution over lower-level frameworks, you might use one or the other or both to facilitate GoingThroughCustoms. --PhilipEskelin So is GoingThroughCustoms a force, rather than a pattern? --NatPryce