Sha256: 1dcc69a7b75bf404a9299554fb9e6dfe5c6d9bd727124e3ecbc944c4ecc98dc5

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

The _service locator_ design pattern can be considered a subset of dependency injection. Because it is simpler, it is as good of a place to start teaching DI as any.

To demonstrate both techniques, we'll pretend we're going to write an online forum application. To start, let's come up with a rough design by cataloging the components we'll need.

* @Logger@. This will be used to write messages to a file.
* @Authenticator@. This will be used to validate whether a user is who they say they are.
* @Database@. This encapsulates access to the database that will store our forum data.
* @Session@. This represents a single user's session.
* @View@. The presentation manager, used to render pages to the user.
* @Application@. The controller that ties it all together.

(Of course, a _real_ online forum application would be significantly more complex, but the above components will do for our purposes.)

The dependencies between these components are:

* @Authenticator@ _has_ @Database@ (for querying user authentication information) and @Logger@
* @Database@ _has_ @Logger@ (for indicating database accesses and query times)
* @Session@ _has_ @Database@ (for storing session information) and @Logger@
* @Application@ _has_ @Database@, @View@, @Session@, and @Authenticator@, and @Logger@

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
needle-1.0.0 doc/manual/parts/03_overview.txt
needle-1.1.0 doc/manual/parts/03_overview.txt
needle-1.2.0 doc/manual/parts/03_overview.txt
needle-1.3.0 doc/manual/parts/03_overview.txt
needle-1.2.1 doc/manual/parts/03_overview.txt