忍者ブログ

いけいけ理系NEO

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

Javaを学ぶ その3

題材は、「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. A class can provide a public static factory method, which is
simply a static method that returns an instance of the class.


日本語でのポイント

constructorのかわりに、static factory methodを利用する。

クライアントがあるクラスのインスタンスを取得する、一般的な方法は、public なconstructorを利用することである。
しかし、プログラマが知るべきテクニックは、他にもある。
クラスは、public static factory methodを提供することができる。これは、クラスのインスタンスを返すものである。

解説

static な methodは、スピードとかメモリ等のメリットがあるような気がします。
たしかに、知っておくべきテクニックかと思います。



PR

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で作る以外の方法で作ることは、プログラムを作る、読む上で、必須の知識だと思います。

Javaを学ぶ その1


インターネットに公開されている情報工学の論文を読んで、

情報工学と英語を一緒に学んでみたいと思います。

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

CHAPTER2

Creating and Destroying Objects

THIS chapter concerns creating and destroying objects: when and how to create them, when and how to avoid creating them, how to ensure they are destroyed in a timely manner, and how to manage any cleanup actions that must precede their destruction.


日本語でのポイント

この章は、オブジェクトの生成と破棄を扱う。
いつ、どんな方法で、オブジェクトを作成すればよいか、
いつ、どんな方法は、オブジェクトの生成をさけるべきか、
適切なタイミングで破棄されることを保証するには、どうすればよいか、
破棄の前のクリーンアップをマネジメントする方法は、
を扱う。


解説

オブジェクトの生成と破棄は、レスポンスや、メモリの容量管理に大きく影響するため、
重要なネタなのだと思います。

newで作るだけではない、と思います。