IT翻訳 Nobuyuki の仕事部屋

ボランティアでソフトウエアーローカライズのために翻訳をしている。

Mozilla DOM Hacking Guide: Introduction to XPCOM16

2006-01-25 23:57:24 | InDraft
寒いとつい億劫になって庭の手入れもおろそかになった結果、雑草がぼうぼうのまま冬枯れてしまった。すぐにしなければならないのは、草刈り、バラの剪定と施肥。きちんとしておかないと、春になって可憐な花をめでることが出来ない。

ところで、バラを美しく咲かせようとすると、剪定や施肥、駆虫処理など手がかかるが、花のなかには何の手入れもしないのに、毎年春になると常連客のように必ず顔を見せる宿根草がある。ヒマヤラユキノシタ:キャベツみたいな大きな葉を持ち、濃いピンクの小さな花を咲かせる。家内の実家から株分けをしてもらって早くも10年。ほとんど毎年咲いている。

株をくれた義母はもういない。花だけが毎年我が家に春を告げに訪れる。その間、子は育ち、義母は故人となり、時は確実に経過した。今年もあの花は咲くであろうか。妻も私も10歳年を取ったが、毎年見る花は永遠に同じ花のように思える。変わらない植物が変わっていく人の営みを見つめているかのようである。ああ、所業無常。(・O・)
-----------------------------------------------------------------------

原文:  青色表示
訳文:  黒色表示
注記/訂正: 赤色表示

Let's assume we have the real class nsFoo which inherits from the real class nsBar. Let's also assume that nsFoo implements the interface nsIFoo. One possible way for nsFoo to implement nsIFoo is to forward the methods on the interface to the implementation of those methods on the class nsBar.

// Interface nsIFoo in XPIDL (stripped down) 
interface nsIFoo {
attribute type prop;
void meth();
};

class nsBar {
NS_IMETHOD GetProp();
NS_IMETHOD SetProp();
NS_IMETHOD Meth();
};

class nsFoo : public nsIFoo,
public nsBar {
// definition of the nsFoo class
};

nsFoo::GetProp() { return nsBar::GetProp(); }
nsFoo::SetProp() { return nsBar::SetProp(); }
nsFoo::Meth() { return nsBar::Meth(); }


実際のクラス nsBar を継承する実際のクラス nsFoo があると仮定しましょう。また nsFoo が nsIFoo インターフェイスを実装するとも仮定しましょう。nsFoo が nsIFoo を実装する可能性の 1 つは、 nsIFoo インターフェイスのメソッドを、クラス nsBar のこれらの同じメソッドの実装において、転送することです

//XPIDLでの nsIFoo インターフェイス(最低限の実装)   
interface nsIFoo {
attribute type prop;
void meth();
};

class nsBar {
NS_IMETHOD GetProp();
NS_IMETHOD SetProp();
NS_IMETHOD Meth();
};

class nsFoo : public nsIFoo,
public nsBar {
//nsFoo クラスの定義 
};

nsFoo::GetProp() { return nsBar::GetProp(); }
nsFoo::SetProp() { return nsBar::SetProp(); }
nsFoo::Meth() { return nsBar::Meth(); }


For such code to work, nsBar of course has to implement GetProp, SetProp, and Meth. Note that nsBar implements the methods of the interface nsIFoo, but does not inherit from that interface. This is the only case where you would use interface forwarding.

このようなコードが機能するのに nsBar はもちろん GetProp、 SetProp、 Meth を実装しなければなりません。注意が必要なのは、nsBar は nsIFoo インターフェイスのメソッドを実装しますが、nsIFoo インターフェイスを継承しません。 そしてこの場合だけインターフェイス転送を使用できます。  

To be continued tomorrow! Bye.