Skip to content

Commit 03f075c

Browse files
stevepiercyjensens
andauthored
Update docs/backend/behaviors.md
Co-authored-by: Jens W. Klein <[email protected]>
1 parent e320c3f commit 03f075c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/backend/behaviors.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,18 @@ When you travel to another country, you may need an outlet adapter for the outle
304304
For example, assume you have a device that has plug for Schuko outlets, and in Italy there are Type L outlets.
305305
If we were to represent the behavior of choosing the correct power adapter in Plone, you would do the following.
306306

307-
- Call `getAdapter(context, ITypeL)` to determine the type of adapter needed for the electric outlet's interface.
308-
- Call `getAdapter(context, ISchuko) to determine the type of adapter that will accept your device's plug.
309-
- You choose the correct electrical adapter to use, and plug that into the wall outlet.
310-
This is similar to calling an abstract factory which returns the correct adapter to use.
311-
This interface provides an ISchuko adapter.
312-
- Finally to use the new interface, you plug in your Schuko plug into the adapter to get power to your device.
307+
- You need an electrical adapter for your Schuko plug.
308+
1. you look at the outlet and see it is TypeL.
309+
2. you look in your box containing different adapters and choose one the correct electrical adapter to use, and
310+
3. plug that into the wall outlet.
311+
4. Finally you can use your Schuko providing device on an Italian TypeL outlet.
312+
- In Python you call `getAdapter(context, ISchuko)` (context is here the outlet) which then
313+
1. determine the type of interface provided by the `context` and as a result it finds `ITypeL`.
314+
2. looks in the component registry if there is a class that adapts to `ITypeL` and at the same time provides the requested `ISchuko`.
315+
3. initializes the adapter class with the context and return it as the result
316+
4. Finally the `ISchuko` providing adapter can be used on a `ITypeL` providing context.
317+
318+
This process of choosing the right adapter based on the information of the context and the requested interface implements the design pattern of an abstract factory.
313319

314320
Similarly, using the {ref}`behavior code example <behavior-code-example>` above:
315321

0 commit comments

Comments
 (0)