Out of Memory

本ブログは更新を停止しました。Aerieをよろしくお願いいたします。

目次

Blog 利用状況

ニュース

2009年3月31日
更新を停止しました。引き続きAerieを御愛顧くださいませ。
2009年2月3日
原則としてコメント受付を停止しました。コメントはAerieまでお願いいたします。
詳細は2月3日のエントリをご覧ください。
2008年7月1日
Microsoft MVP for Developer Tools - Visual C++ を再受賞しました。
2008年2月某日
MVPアワードがVisual C++に変更になりました。
2007年10月23日
blogタイトルを変更しました。
2007年7月1日
Microsoft MVP for Windows - SDKを受賞しました!
2007年6月20日
スキル「ニュース欄ハック」を覚えた!
2006年12月14日
記念すべき初エントリ
2006年12月3日
わんくま同盟に加盟しました。

カレンダー

中の人

αετο? / aetos / あえとす

シャノン? 誰それ。

顔写真

埼玉を馬鹿にする奴は俺が許さん。

基本的に知ったかぶり。興味を持った技術に手を出して、ちょっと齧りはするものの、それを応用して何か形にするまでは及ばずに飽きて放り出す人。

書庫

日記カテゴリ

リスコフの置換原理

#IDisposableの第2回はちょっと待って。

オブジェクト指向の重要な原則の一つに、「リスコフの置換原理」がある。
基本的なことなので、知らない人はぜひこの機会に調べて身につけてほしいが、ここでも簡単に説明しよう。

極めて簡潔に言えば、「型Tのオブジェクトを使用できるところではどこでも、Tの派生型を使用できなければならない」というのが、この原則だ。
よく例に出されるのは、「型Tのオブジェクトを引数に取るメソッドには、Tの任意の派生型のオブジェクトを渡せなければならない」というやつ。

だが、これは引数にとどまらない。
戻り値についても同じことが言える。つまり「型Tのオブジェクトを戻り値として返すメソッドは、Tの任意の派生型を返せるようになっていなければならない」だ。

この制約が課される対象は2つある。
例示では、型Tと、その派生型にしか言及されない場合が多い。つまり、「Tの派生型は、T型のオブジェクトの代わりに使われても問題ない作りになっていなければならない」ということだ。これが1つ。
もう1つは、それを受け取る側だ。引数を例にすれば、「型Tのオブジェクトを引数に取るメソッドは、Tの任意の派生型を受け取っても正しく動作しなければならない」。

即ち、リスコフの置換原理は、以下の4つ(例外にも言及する場合は2つ加えて6つ。プロパティは割愛)の場合に成り立つ。

  • 型Tから派生した型Sのオブジェクトは、型Tのオブジェクトを引数に取るメソッドに渡しても正しく動作しなければならない。
  • 型Tから派生した型Sのオブジェクトは、型Tのオブジェクトを戻り値として返すメソッドから返されても、正しく動作しなければならない。
  • 型Tのオブジェクトを引数に取るメソッドは、Tから派生した型Sのオブジェクトを渡されても、正しく動作しなければならない。
  • 型Tのオブジェクトを返すメソッドの呼び出し側は、Tから派生した型Sのオブジェクトを返されても、正しく動作しなければならない。

引数や戻り値を受け取る側については例示が少ないため、適用されないと思っていたら間違いだ。
そして、受け取る側についても成り立つということは、「(特別な場合を除き)受け取る側は、受け取った引数や戻り値をダウンキャストしてはならない」ということになる。

投稿日時 : 2007年4月16日 11:41

Feedback

# re: 昔見た問題(その2) 2007/04/19 12:14 R.Tanaka.Ichiro's Blog

re: 昔見た問題(その2)

# 昔見た問題(その2) 2007/04/20 10:07 R.Tanaka.Ichiro's Blog

昔見た問題(その2)

# re: リスコフの置換原理 2017/11/28 12:04 cc

http://www.reebokoutlet.us.org
http://www.adidasnmds.com
http://www.kyrie3.us.com
http://www.fitflops-saleclearance.us.com
http://www.adidassuperstar.us.com
http://www.boostyeezy.us.com
http://www.yeezyboost350v2.org.uk
http://www.goldengoose-outlet.us.com
http://www.rosherun.us.com
http://www.adidasnmdrunner.us.com
http://www.hermes-birkin.us.com
http://www.outlettimberland.us.org
http://www.balenciagashoes.us.com
http://www.stephencurry-shoes.us.com
http://www.nikerosheone.co.uk
http://www.nikemercurial.us.com
http://www.tomford-sunglasses.us.com
http://www.adidasstansmith.us.com
http://www.nikeairmax2018.us.com
http://www.nikezoom.us.com
http://www.toryburchshoes.org.uk
http://www.michaelkors-outletsonline.us.com
http://www.toryburchshoes.us
http://www.hermes-belt.co.uk
http://www.longchamps.org.uk

# For latest news you have to pay a visit world-wide-web and on the web I found this web page as a finest site for most recent updates. 2019/05/03 17:41 For latest news you have to pay a visit world-wide

For latest news you have to pay a visit world-wide-web and on the web I found this web page as a finest site
for most recent updates.

# Hmm is anyone else encountering problems with the images on this blog loading? I'm trying to find out if its a problem on my end or if it's the blog. Any feedback would be greatly appreciated. 2019/05/08 21:16 Hmm is anyone else encountering problems with the

Hmm is anyone else encountering problems with the images on this blog loading?
I'm trying to find out if its a problem on my end or if it's the blog.
Any feedback would be greatly appreciated.

# If some one desires expert view about blogging afterward i recommend him/her to visit this webpage, Keep up the good job. 2019/05/14 8:43 If some one desires expert view about blogging af

If some one desires expert view about blogging
afterward i recommend him/her to visit this webpage, Keep up the good job.

# Howdy! This article could not be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I'll forward this article to him. Fairly certain he's going to have a great read. Many thanks for 2019/07/30 22:23 Howdy! This article could not be written any bette

Howdy! This article could not be written any better! Reading
through this post reminds me of my previous
roommate! He continually kept talking about this. I'll forward this article
to him. Fairly certain he's going to have a great read.
Many thanks for sharing!

# Howdy! This article could not be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I'll forward this article to him. Fairly certain he's going to have a great read. Many thanks for 2019/07/30 22:24 Howdy! This article could not be written any bette

Howdy! This article could not be written any better! Reading
through this post reminds me of my previous
roommate! He continually kept talking about this. I'll forward this article
to him. Fairly certain he's going to have a great read.
Many thanks for sharing!

# Howdy! This article could not be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I'll forward this article to him. Fairly certain he's going to have a great read. Many thanks for 2019/07/30 22:25 Howdy! This article could not be written any bette

Howdy! This article could not be written any better! Reading
through this post reminds me of my previous
roommate! He continually kept talking about this. I'll forward this article
to him. Fairly certain he's going to have a great read.
Many thanks for sharing!

# Howdy! This article could not be written any better! Reading through this post reminds me of my previous roommate! He continually kept talking about this. I'll forward this article to him. Fairly certain he's going to have a great read. Many thanks for 2019/07/30 22:26 Howdy! This article could not be written any bette

Howdy! This article could not be written any better! Reading
through this post reminds me of my previous
roommate! He continually kept talking about this. I'll forward this article
to him. Fairly certain he's going to have a great read.
Many thanks for sharing!

タイトル
名前
Url
コメント