Skip to content

Commit 6d4ba37

Browse files
committed
Translate Factory Method
1 parent ebfb9d3 commit 6d4ba37

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

README-ja-jp.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ _このドキュメントは[AngularJS in Patterns](https://github.com/mgechev/a
1717
* [サービス](#サービス)
1818
* [AngularJSのパターン](#angularjs-patterns)
1919
* [サービス](#services-1)
20-
* [シングルトン](#singleton)
21-
* [Factory Method](#factory-method)
20+
* [シングルトン](#シングルトン)
21+
* [ファクトリ・メソッド](#ファクトリ・メソッド)
2222
* [Decorator](#decorator)
2323
* [Facade](#facade)
2424
* [Proxy](#proxy)
@@ -259,7 +259,7 @@ function MyCtrl(developer) {
259259

260260
#### シングルトン
261261

262-
> シングルトン・パターンはクラスのインスンタンスを1つに制限するデザイン・パターンです。システムを通してアクションを調整するオブジェクトが1つで良い場合に役に立ちます。この考え方はしばしばシステムに対して、オブジェクトを1つにして効率的に稼働させることや、オブジェクトの数を一定の数以下にを制限することに一般化されます。
262+
>シングルトン・パターンはクラスのインスンタンスを1つに制限するデザイン・パターンです。システムを通してアクションを調整するオブジェクトが1つで良い場合に役に立ちます。この考え方はしばしばシステムに対して、オブジェクトを1つにして効率的に稼働させることや、オブジェクトの数を一定の数以下にを制限することに一般化されます。
263263
264264
下記のUMLダイアグラムはシングルトンのデザイン・パターンを表しています。
265265

@@ -309,20 +309,20 @@ function getService(serviceName) {
309309

310310
このトピックに関する更に一歩踏み込んだ議論のために、Google Testing blogのMisko Heveryの [記事](http://googletesting.blogspot.com/2008/05/tott-using-dependancy-injection-to.html) を考慮にいれましょう。
311311

312-
#### Factory Method
312+
#### ファクトリ・メソッド
313313

314-
>The factory method pattern is a creational pattern, which uses factory methods to deal with the problem of creating objects without specifying the exact class of object that will be created. This is done by creating objects via a factory method, which is either specified in an interface (abstract class) and implemented in implementing classes (concrete classes); or implemented in a base class, which can be overridden when inherited in derived classes; rather than by a constructor.
314+
>ファクトリ・メソッド・パターンは生成のパターンです。生成のパターンは生成するクラス指定のないオブジェクトを生成する際に生じる問題をうまく扱うためにファクトリ・メソッドを利用します。コンストラクタではなく、インターフェイス(抽象クラス)で指定されているファクトリメソッド、実装クラス(具象クラス)に実装されているファクトリメソッド、また、継承される可能性もあるのですが、ベースクラスに実装されているファクトリメソッドを通してオブジェクトが生成される場合に利用されます。
315315
316316
![Factory Method](https://rawgit.com/mgechev/angularjs-in-patterns/master/images/factory-method.svg "Fig. 2")
317317

318-
Lets consider the following snippet:
318+
次のスニペットを考えてみましょう:
319319

320320
```JavaScript
321321
myModule.config(function ($provide) {
322322
$provide.provider('foo', function () {
323323
var baz = 42;
324324
return {
325-
//Factory method
325+
//ファクトリ・メソッド
326326
$get: function (bar) {
327327
var baz = bar.baz();
328328
return {
@@ -335,11 +335,11 @@ myModule.config(function ($provide) {
335335

336336
```
337337

338-
In the code above we use the `config` callback in order to define new "provider". Provider is an object, which has a method called `$get`. Since in JavaScript we don't have interfaces and the language is duck-typed there is a convention to name the factory method of the providers that way.
338+
新しい "プロバイダ" を定義するために、上記のコードで `config` コールバックを利用しています。プロバイダは `$get` メソッドを持っているオブジェクトです。JavaScriptでインターフェイスを持たず、ダックタイプされているので、このようにプロバイダのファクトリ・メソッドを名付ける慣例があります。
339339

340-
Each service, filter, directive and controller has a provider (i.e. object which factory method, called `$get`), which is responsible for creating the component's instance.
340+
サービス、フィルタ、ディレクティブ、コントローラはそれぞれコンポーネントのインスタンスを生成する責務を負うプロバイダ( `$get` を持つオブジェクト)を持ちます。
341341

342-
We can dig a little bit deeper in AngularJS' implementation:
342+
AngularJSの実装をもう少し深く探っていくことが出います:
343343

344344
```JavaScript
345345
//...
@@ -375,29 +375,29 @@ function invoke(fn, self, locals, serviceName){
375375
);
376376
}
377377
if (!fn.$inject) {
378-
// this means that we must be an array.
378+
// これは配列でなければいけないことを意味しています
379379
fn = fn[length];
380380
}
381381

382382
return fn.apply(self, args);
383383
}
384384
```
385385

386-
From the example above we can notice how the `$get` method is actually used:
386+
上記の例から、 `$get` メソッドが実際に利用されていることを知ることができます:
387387

388388
```JavaScript
389389
instanceInjector.invoke(provider.$get, provider, undefined, servicename)
390390
```
391391

392-
The snippet above calls the `invoke` method of `instanceInjector` with the factory method (i.e. `$get`) of given service, as first argument. Inside `invoke`'s body `annotate` is called with first argument the factory method. Annotate resolves all dependencies through the dependency injection mechanism of AngularJS, which was considered above. When all dependencies are resolved the factory method is being called: `fn.apply(self, args)`.
392+
上記のスニペットは `instanceInjector``invoke` メソッドを最初の引数にサービスのファクトリ・メソッド( `$get` )を指定して呼んでいます。 `invoke`メソッドの中では、最初の引数にファクトリメソッドを指定して `annotate` が呼ばれています。アノテートはAngularJSの依存性の注入メカニズムを通して全ての依存性を解決します。全ての依存性の解決ができた時、ファクトリ・メソッドが呼ばれます: `fn.apply(self, args)`
393393

394-
If we think in terms of the UML diagram above we can call the provider a "ConcreteCreator" and the actual component, which is being created a "Product".
394+
上記のUMLダイアグラムの観点から考えると、プロバイダを "ConcreteCreator" と呼ぶことができます。そして、実際のコンポーネントは作られた "Product" となります。
395395

396-
There are a few benefits of using the factory method pattern in this case, because of the indirection it creates. This way the framework can take care of the boilerplates during the instantiation of new components like:
396+
ファクトリ・メソッドの間接性にファクトリ・メソッドを使ういくつかの利点があります。この方法で、フレームワークは新しいコンポーネントを生成する際の基本的な中身に注意を払うことができます:
397397

398-
- The most appropriate moment, when the component needs to be instantiated
399-
- Resolving all the dependencies required by the component
400-
- The number of instances the given component is allowed to have (for services and filters only a single one but multiple for the controllers)
398+
- コンポーネントがインスタンス化される最も適切なタイミング
399+
- コンポーネントに必要とされるすべての依存性の解決
400+
- コンポーネントが持つことを許されているインスタンスの数(サービスとフィルタは1つ。コントローラは複数)
401401

402402
#### Decorator
403403

0 commit comments

Comments
 (0)