忍者ブログ

いけいけ理系NEO

情報処理試験など、理系の試験対策、関連知識、日記などです

Javaを学ぶ その2

題材は、「Effective Java 2nd Edition」です。

Item 1: Consider static factory methods instead of constructors

The normal way for a class to allow a client to obtain an instance of itself is to provide a public constructor. There is another technique that should be a part of every programmer’s toolkit.

日本語でのポイント

1:コンストラクタの代わりに、static factory methods を考えよう

クライアントが、あるクラスを生成するための通常の手段は、public constructorを使うことである。
しかし、役立つ他のテクニックもある。

解説

いわゆる newで作る以外の方法で作ることは、プログラムを作る、読む上で、必須の知識だと思います。
PR