レベルエンター山本大のブログ

面白いプログラミング教育を若い人たちに

BLOCKVROCKリファレンス目次はこちら

[翻訳]Guice User's Guide ■12. DRY (Don't Repeat Yourself)

DRY (自分で書いたものを繰り返すな!)

Repeating "binder" over and over for each binding can get a little tedious. Guice provides a Module support class named AbstractModule which implicitly gives you access to Binder's methods. For example, we could extend AbstractModule and rewrite the above binding as:

それぞれのバインドのために、“binder”を何度も繰り返すのは、ちょっと退屈になりがちです。GuiceはModuleをサポートするためのクラスとして、暗黙的にBinderにアクセスするメソッドがあるAbstractModuleと呼ばれるクラスを提供しています。

bind(Service.class).to(ServiceImpl.class);

We'll use this syntax throughout the rest of the guide.

このガイドの以降の部分では、この構文を使用するつもりです。