投稿数 - 437, コメント - 53761, トラックバック - 156

プロパティとフィールドの違い

http://f57.aaa.livedoor.jp/~jeanne/bbs/faq.cgi?mode=al2&namber=9549 より

フィールドは一切公開せず、プロパティで包んであげて公開するのが望ましいとされているが、律儀に全てに適応させるのは、はっきり言って無駄だと思う。

public class TestClass {
    private int _id;
    private string _name;
    private Data _data;
 
    public int ID {
        get { return _id; }
        set { _id = value; }
    }
 
    public string Name {
        get { return _name; }
        set { _name = value; }
    }
 
    public Data Data {
        get { return _data; }
        set { _data = value; }
    }
}

こんなコードは労力の無駄。フィールドとプロパティに何の違いがあろうか。「売り物のライブラリでも作っているんですか?」と言いたい。アプリケーションを書いていていつでもコードが触れる状態ならば、必要になった時に初めてプロパティにすれば良いのだ。

しかし、
http://blogs.wankuma.com/shuujin/archive/2006/08/13/36108.aspx
のように、プロパティしか引っ張ってこない奴がいるから厄介だ。私は一種の不具合だとすら思う。リフレクションでフィールドとプロパティを区別しないで欲しい。

後は、getter しか設けたくないならプロパティにすれば良い。

投稿日時 : 2006年12月22日 23:55

フィードバック

# re: プロパティとフィールドの違い

です.です。DEATH.
ちゃんとプロパティの一覧と、フィールドの一覧から引っ張れ!!
とおもうけど、フィールド公開しつつプロパティも作っててバグの温床とかになるからっていうところが真意なんだろうなぁ。
2006/12/23 9:37 | 中博俊

# re: プロパティとフィールドの違い

readonly にしたいだけでというのはちょいと不適切で、
エラー実装などの副作用が欲しいときも含まなければならない。
それを抜きにしても、プロパティは概念的な問題もあります。

というか、protected 以上のフィールドは定義しないでください。
と MSDN には書いてあります。
2006/12/23 10:21 | じゃんぬねっと

# プロパティとフィールドの違い

プロパティとフィールドの違い
2006/12/23 10:37 | .COM -どっとこむ-

# プロパティとフィールドの違い

プロパティとフィールドの違い
2006/12/23 10:43 | .COM -どっとこむ-

# re: プロパティとフィールドの違い

>ちゃんとプロパティの一覧と、フィールドの一覧から引っ張れ!!
>とおもうけど、フィールド公開しつつプロパティも作っててバグの温床とかになるからっていうところが真意なんだろうなぁ。

Public 限定で引っ張れば問題ないと思いますが(多分してると思うけど)真意はどうなんでしょうね。

>readonly にしたいだけでというのはちょいと不適切で、
>エラー実装などの副作用が欲しいときも含まなければならない。

勿論そうですね。プロパティ的な使い方をしていればいいんですけど、何もしていないプロパティが大量にあるのもどうかと。
後でフィールドからプロパティに変更しても、インターフェースは変わらないからリコンパイルだけで済みますしね。

>というか、protected 以上のフィールドは定義しないでください。
>と MSDN には書いてあります。

多分、これのせいで無闇にプロパティにしてしまうんだと思います。クラスライブラリ作成者向けのデザインガイドかな。
2006/12/23 11:02 | 囚人

# re: プロパティとフィールドの違い

ひろえむさんが話題にしてたので探しちゃった。

囚人さんのご意見に同意します。

できるだけ単純に書き、必要が生じたときにだけ必要な分だけ複雑化したほうがいいと思います。
2006/12/23 16:49 | tatsugoro

# re: プロパティとフィールドの違い

>tatsugoroさん

ありがとうございます。
まぁ、迷う人はとりあえずプロパティにしておけば間違いありません、で納まるんですけどね。
2006/12/23 17:12 | 囚人

# re: プロパティとフィールドの違い

私はプロパティ派です。
詳細は、ブログにて。
http://blogs.wankuma.com/pandora/archive/2006/12/23/53180.aspx
2006/12/23 17:21 | Pandora

# プロパティとフィールドの違い - その 2

プロパティとフィールドの違い - その 2
2006/12/23 18:12 | 囚人のジレンマな日々

# プロパティとフィールドの違い - その 2

プロパティとフィールドの違い - その 2
2006/12/25 9:15 | 囚人のジレンマな日々

# バーバリー コート アウトレット

今日は~^^またブログ覗かせていただきました。よろしくお願いします。
2012/11/06 21:14 | http://burberry.suppa.jp/

# At this time I am going away to do my breakfast, once having my breakfast coming again to read more news.

At this time I am going away to do my breakfast, once having my breakfast coming again to read more news.

# What i do not understood is in reality how you're no longer actually a lot more neatly-appreciated than you may be now. You are very intelligent. You know therefore significantly in relation to this matter, produced me in my opinion believe it from a lo

What i do not understood is in reality how you're no longer actually
a lot more neatly-appreciated than you may be now. You are very intelligent.
You know therefore significantly in relation to this matter, produced me in my opinion believe it from a lot of varied angles.
Its like men and women don't seem to be fascinated until it
is something to accomplish with Lady gaga!
Your personal stuffs excellent. All the time care for it up!

# Wow, this article is good, my sister is analyzing such things, therefore I am going to inform her.

Wow, this article is good, my sister is analyzing such things, therefore I am going to
inform her.

# QeCsnUIIlayPVlH

MHnfJt I was suggested this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my difficulty. You are amazing! Thanks!
2018/12/19 22:25 | https://www.suba.me/

# Hi there, I discovered your website by way of Google even as searching for a similar matter, your web site came up, it seems to be good. I have bookmarked it in my google bookmarks. Hi there, simply changed into aware of your weblog thru Google, and loca

Hi there, I discovered your website by way of Google even as searching
for a similar matter, your web site came up, it seems to be good.
I have bookmarked it in my google bookmarks.
Hi there, simply changed into aware of your weblog thru Google, and located that it is
truly informative. I am going to watch out for brussels. I will be grateful if you happen to proceed this
in future. A lot of other people will be benefited out of your writing.
Cheers!

# It's enormous that you are getting thoughts from this post as well as from our dialogue made at this place.

It's enormous that you are getting thoughts from this post as
well as from our dialogue made at this place.

# When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment. Perhaps there is a means you are able to remove me f

When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment.
Perhaps there is a means you are able to remove me from that service?
Appreciate it!

# When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment. Perhaps there is a means you are able to remove me f

When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment.
Perhaps there is a means you are able to remove me from that service?
Appreciate it!

# When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment. Perhaps there is a means you are able to remove me f

When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment.
Perhaps there is a means you are able to remove me from that service?
Appreciate it!

# When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment. Perhaps there is a means you are able to remove me f

When I initially commented I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I get four emails with the exact same comment.
Perhaps there is a means you are able to remove me from that service?
Appreciate it!

# You really make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand. It seems too complicated and extremely broad for me. I'm looking forward for your next post, I'll try to get the

You really make it seem so easy with your presentation but I find this matter to be really something which I think I would never
understand. It seems too complicated and extremely broad for me.
I'm looking forward for your next post, I'll try to get the hang of it!

# Why people still use to read news papers when in this technological globe the whole thing is existing on net?

Why people still use to read news papers when in this technological globe the whole thing
is existing on net?

# Why people still use to read news papers when in this technological globe the whole thing is existing on net?

Why people still use to read news papers when in this technological globe the whole thing
is existing on net?

# Why people still use to read news papers when in this technological globe the whole thing is existing on net?

Why people still use to read news papers when in this technological globe the whole thing
is existing on net?

# Why people still use to read news papers when in this technological globe the whole thing is existing on net?

Why people still use to read news papers when in this technological globe the whole thing
is existing on net?

# mkuahGhkKoJylfo

I think other site proprietors should take this website as an model, very clean and great user friendly style and design, as well as the content. You are an expert in this topic!
2021/07/03 2:40 | https://amzn.to/365xyVY

# jowXVEOSWubDfiHric

Really appreciate you sharing this blog post.Thanks Again. Fantastic.

# Illikebuisse xxtvc

how to make hydroxychloroquine https://www.pharmaceptica.com/
2021/07/05 0:30 | pharmacepticacom

# re: ??????????????

where to get chloroquine https://chloroquineorigin.com/# hydroxyclorine
2021/07/08 4:29 | hydrocloroquine

# re: ??????????????

chloroquine cvs https://chloroquineorigin.com/# hcqs 200
2021/07/09 8:47 | hydrocyhloroquine

# re: ??????????????

is chloroquine available over the counter https://chloroquineorigin.com/# methotrexate side effects usmle

# re: ??????????????

chloroquine phosphate vs chloroquine sulphate https://chloroquineorigin.com/# hydroxychloroquine sulfate side effects

# re: ??????????????

chloroquine natural sources https://chloroquineorigin.com/# hydroxyquine side effects
2021/07/25 12:37 | hydroxychloroquine sulfate

# qcdkvaxiwhus

https://aralenquinesab.com/ how to make hydroxychloroquine at home
2021/11/26 23:54 | dwedaybedp

# rcgxeuqzolmy

https://chloroquinehydro.com/ hydroxychloroquine sulfate tablets
2021/11/27 6:37 | cegonkia

# tqaisxdlvwlg

https://hydroaraleneth.com/ hydroxychloroquine cost at costco
2021/12/04 5:39 | dwedayvinq

# vdbekuhcwvbd

what is hydroxychloroquine 200 mg https://keys-chloroquineclinique.com/
2022/05/06 21:28 | dfzqsd

# hynznaicdwka

hydoxychloroquine https://keys-chloroquinehydro.com/
2022/05/07 6:04 | gmufsq

# Test, just a test

canadian customs pills vitamins http://candipharm.com/#
2022/12/13 0:50 | candipharm

# hydroxychloroquine tablets 200mg

https://hydroxychloroquinex.com/ cheap hydroxychloroquine
2022/12/29 7:34 | MorrisReaks

# ロレックス偽物時計

商品到着まで非常にスムーズで、安心して買い物を終えることができました。またこちらからのお願いに対しても、細やかな心遣いをいただきありがとうございました。また利用させていただきます。
送料&代引手数料無料☆新品ランクSA【送料無料】★ルイヴィトン★モノグラム★ポルトモネ・プラ★コインケース/小銭入れ★M61930★
本日商品が到着しました。とても状態の良い品物で、プレゼントしたヴィトン好きの妻も大喜びでした。こちらのショップの商品ランクの正確さに大満足の買い物でした。
ロレックス偽物時計 https://www.ginza24.com/product/detail/3935.htm
2023/03/25 0:33 | izfzllda@aol.jp

コメントの投稿

タイトル
名前
URL
コメント