代码之家  ›  专栏  ›  技术社区  ›  therealhoff

信息隐藏和属性

oop
  •  3
  • therealhoff  · 技术社区  · 16 年前

    信息隐藏是否意味着我应该最小化类的属性数量?是吗?您倾向于使用方法使类成为私有字段吗?

    8 回复  |  直到 16 年前
        1
  •  1
  •   Shog9    16 年前

        2
  •  6
  •   Ben Hoffstein    16 年前

        3
  •  2
  •   moffdub    16 年前
        4
  •  1
  •   lubos hasko    16 年前

        5
  •  0
  •   Ian P    16 年前

        6
  •  0
  •   Charles Graham    16 年前

        7
  •  0
  •   Arthur Vanderbilt    16 年前

        8
  •  0
  •   Adam Bellaire    16 年前

    private int _myInt;
    public int MyInt
    {
      get { return _myInt; }
      set { _myInt = value; }
    }
    

    public int MyInt { get; set; }
    

    public int MyInt
    {
      get { return _myInt; }
      set
      {
        _myInt = (value % 2 == 0) ? value : _myInt;
      }
    }