In the MyApplication
example (and in many applications),
the only
thing we need to
consider is
what our code does, not how objects are created from the MyResource
class and how the respond
method is invoked. However, the mechanisms behind all these things are
not magic - the adapter
code is responsible for all of
this. Let us
turn the diagram of components on its side and investigate what happens
when a request is sent to the application from a user:
Server environment | Adapter | Application |
---|---|---|
The request is received and sent to the adapter... | The adapter creates a resource object in the application... | A resource object is created and initialised. |
The adapter
calls the respond method on the new resource... |
The code
within the resource's respond method is executed. |
So it is the responsibility of the adapter to create at least one resource object so that the application code may be executed when a request is received from a user. This is described in the deployment documentation.
In more complicated applications, there may be a need to create a number of resource objects and possibly to do so dynamically within an application itself, but this is not usually interesting or relevant to think about when writing your first application - see "Treating the Path Like a Filesystem" for a discussion of creating new resource objects both in the adapter code and dynamically within applications.