クラス ZipFile とクラス Content があるとします。
ZipFile には、zip アーカイブ内のすべてのファイルの内容を読み取り、それを Content オブジェクトに入れるための load() メソッドがあります。
最も適切な OOP 設計は何ですか?
1) ZipFile.load() は Content オブジェクトを作成します
class ZipFile
{
public function load()
{
// Load all files in zip
// ...
Content content = new Content();
content->set(data);
return( content );
}
}
ZipFile zf = new ZipFile();
Content ct = zf->load();
ct->print();
B) ZipFile コンストラクターに Content オブジェクトを指定して入力する
class ZipFile
{
private Content content;
public function ZipFile(content) // constructor
{
this->content = content;
}
public function load()
{
// Load all files in zip
// ...
this->content->set(data);
}
}
Content ct = new Content();
ZipFile zf = new ZipFile(ct);
zf->load();
ct->print();
基本的にオブジェクトは分離(疎結合)した方が良いのでしょうか?昔ながらの手続き型プログラマーとして、私は OOP を設計するいくつかの方法に疑問を抱くのを止めることはできません。「これをOOPする最良の方法は何ですか。それを熟考するためのアドバイスはありますか?本ですか?ウェブサイトですか?
ご協力いただきありがとうございます