Skip to content

Commit ebfb9d3

Browse files
committed
シングルトン
1 parent 1c639e1 commit ebfb9d3

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

README-ja-jp.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ _このドキュメントは[AngularJS in Patterns](https://github.com/mgechev/a
1515
* [ディレクティブ](#ディレクティブ)
1616
* [フィルタ](#フィルタ)
1717
* [サービス](#サービス)
18-
* [AngularJS Patterns](#angularjs-patterns)
19-
* [Services](#services-1)
20-
* [Singleton](#singleton)
18+
* [AngularJSのパターン](#angularjs-patterns)
19+
* [サービス](#services-1)
20+
* [シングルトン](#singleton)
2121
* [Factory Method](#factory-method)
2222
* [Decorator](#decorator)
2323
* [Facade](#facade)
@@ -249,32 +249,32 @@ function MyCtrl(developer) {
249249
}
250250
```
251251

252-
## AngularJS Patterns
252+
## AngularJSのパターン
253253

254-
In the next a couple of sections, we are going to take a look how the traditional design and architectural patterns are composed in the AngularJS components.
254+
次の2つのセクションで、伝統的なデザインとアーキテクチャのパターンがAngularJSのコンポーネントの中でどのように構成されているのかを見ていきます。
255255

256-
In the last chapter we are going to take a look at some architectural patterns, which are frequently used in the development of Single-Page Applications with (but not limited to) AngularJS.
256+
最後の章ではAngularJSに限らずシングル・ページ・アプリケーションで頻繁に使われるアーキテクチャのパターンについて見ていきます。
257257

258-
### Services
258+
### サービス
259259

260-
#### Singleton
260+
#### シングルトン
261261

262-
>The singleton pattern is a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects.
262+
> シングルトン・パターンはクラスのインスンタンスを1つに制限するデザイン・パターンです。システムを通してアクションを調整するオブジェクトが1つで良い場合に役に立ちます。この考え方はしばしばシステムに対して、オブジェクトを1つにして効率的に稼働させることや、オブジェクトの数を一定の数以下にを制限することに一般化されます。
263263
264-
In the UML diagram bellow is illustrated the singleton design pattern.
264+
下記のUMLダイアグラムはシングルトンのデザイン・パターンを表しています。
265265

266266
![Singleton](https://rawgit.com/mgechev/angularjs-in-patterns/master/images/singleton.svg "Fig. 1")
267267

268-
When given dependency is required by any component, AngularJS resolves it using the following algorithm:
268+
依存性がコンポーネントに必要とされる際に、AngularJSは次のアルゴリズムを使って依存性の解決を行っています:
269269

270-
- Takes its name and makes a lookup at a hash map, which is defined into a lexical closure (so it has a private visibility).
271-
- If the dependency exists AngularJS pass it as parameter to the component, which requires it.
272-
- If the dependency does not exists:
273-
- AngularJS instantiate it by calling the factory method of its provider (i.e. `$get`). Note that instantiating the dependency may require recursive call to the same algorithm, for resolving all the dependencies required by the given dependency. This process may lead to circular dependency.
274-
- AngularJS caches it inside the hash map mentioned above.
275-
- AngularJS passes it as parameter to the component, which requires it.
270+
- 依存性の名前で語彙のクロージャの中に定義されているハッシュ・マップを検索します(プライベートにアクセスできるようになっています)。
271+
- 依存性がAngularJSの中に存在する場合は、それを必要としているコンポーネントにパラメタとして渡します。
272+
- 依存性が存在しない場合は:
273+
- AngularJSはプロバイダのファクトリ・メソッド( `$get` )を用いてその依存性をインスタンス化します。 依存性のインスタンス化は必要に応じて、同じアルゴリズムを用いて再帰的に行われます。このプロセスは循環依存を起こします。
274+
- AngularJSはそのインスタンスを上述のハッシュ・マップにキャッシュします。
275+
- AngularJSは必要としているコンポーネントにパラメタとしてそのインスタンスを渡します。
276276

277-
We can take better look at the AngularJS' source code, which implements the method `getService`:
277+
`getService` メソッドが実装されている部分のソースコードを見たほうが良いでしょう。
278278

279279
```JavaScript
280280
function getService(serviceName) {
@@ -300,14 +300,14 @@ function getService(serviceName) {
300300
}
301301
```
302302

303-
We can think of each service as a singleton, because each service is instantiated no more than a single time. We can consider the cache as a singleton manager. There is a slight variation from the UML diagram illustrated above because instead of keeping static, private reference to the singleton inside its constructor function, we keep the reference inside the singleton manager (stated in the snippet above as `cache`).
303+
サービスは一度しかインスタンス化されないので、全てのサービスをシングルトンと考えることができます。キャッシュはシングルトンのマネージャと考えることができます。上記のUMLダイアグラムと少し違いがあります。コンストラクタ関数の中のシングルトンオブジェクトにスタティックでプライベートな参照を保つ代わりに、シングルトン・マネージャ(上記のコードの中の `cache` )の中に参照を保ちます。
304304

305-
This way the services are actually singletons but not implemented through the Singleton pattern, which provides a few advantages over the standard implementation:
305+
このように、サービスは実際にはシングルトンですが、シングルトン・パターンを通して実装されているわkではありません。これは、一般的な実装に比べていくつかの利点があります。
306306

307-
- It improves the testability of your source code
308-
- You can control the creation of singleton objects (in our case the IoC container controls it for us, by instantiating the singletons lazy)
307+
- テストをしやすくします。
308+
- シングルトンオブジェクトの生成をコントロールできます(私達のケースでは、IoCコンテナがシングルトンを遅延インスタンス化することでコントロールしています)。
309309

310-
For further discussion on this topic Misko Hevery's [article](http://googletesting.blogspot.com/2008/05/tott-using-dependancy-injection-to.html) in the Google Testing blog could be considered.
310+
このトピックに関する更に一歩踏み込んだ議論のために、Google Testing blogのMisko Heveryの [記事](http://googletesting.blogspot.com/2008/05/tott-using-dependancy-injection-to.html) を考慮にいれましょう。
311311

312312
#### Factory Method
313313

0 commit comments

Comments
 (0)