@@ -295,6 +295,26 @@ In Plone, behaviors can be globally enabled on content types at runtime.
295295With add-ons, behaviors can even be enabled even on a single content object or for a whole subtree in the content hierarchy.
296296
297297### Interfaces and adapters
298+ To explain interfaces and adapters, let's begin with an analogy using electrical systems.
299+
300+ An electrical outlet provides an interface through which electricity passes.
301+ When you travel to another country, you may need an outlet adapter for the outlet (the interface).
302+ For example, assume you have a device that has plug for Schuko outlets, and in Italy there are Type L outlets.
303+ If we were to represent the behavior of choosing the correct power adapter in Plone, you would do the following.
304+
305+ - Call ` getAdapter(context, ITypeL) ` to determine the type of adapter needed for the electric outlet's interface.
306+ - Call `getAdapter(context, ISchuko) to determine the type of adapter that will accept your device's plug.
307+ - You choose the correct electrical adapter to use, and plug that into the wall outlet.
308+ This is similar to calling an abstract factory which returns the correct adapter to use.
309+ This interface provides an ISchuko adapter.
310+ - Finally to use the new interface, you plug in your Schuko plug into the adapter to get power to your device.
311+
312+ Similarly, using the {ref}` behavior code example <behavior-code-example> ` above:
313+
314+ - You would call an abstract factory with ` getAdapter(context, IPriceBehavior) ` to get an adapter.
315+ Although it is an interface, it is more of a shortcut to factory usage.
316+ - The adapter that is specific to the given content type is assigned to the variable ` adapter ` .
317+ Now you can use ` adapter ` for whatever you like.
298318
299319When a behavior is enabled for a particular object, it will be possible to adapt that object to the behavior's interface.
300320Otherwise, when the behavior is disabled, adaptation will fail or falls back to a more generic adapter, if any is registered.
0 commit comments