Information Hiding and Properties

Is information hiding? Should I minimize the number of properties that my classes have? It is right? Are you inclined to make your classes private fields using methods?

+3
source share
8 answers

Ever start a conversation asking, “How are you?”, Just to meet the line of their problems and triumphs, the irritability of pets and uninteresting interests, feelings of insecurity and, possibly, an in-depth review of breakfast with muffins ...

... this is not information hiding. Most of us do not. Children do, at least, until they meet someone who uses all the irrelevant information that they share to hurt or humiliate them somehow ... then they learn to be secretive and paranoid, another step towards adulthood.

, , , , , . , - getters/seters - , " " "", ...

, . , , , , . , , , : , , , , , .

+1

, (, ) . , , (.. " " ). .

+6

. , .

, , , / .

" ..." .

, - . , (UI, ..), , .

+2

, . ,

+1

- "" .

, , , .

0

, . , - :

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

(IIRC, 3.5 ):

public int MyInt { get; set; }

, , , . private, , , :

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

(: , , .)

, . , , , .

0

, . , , , .

0

, , , . , , . ... , , , , . , , , , , . , ( ) , - , .

0
source

Source: https://habr.com/ru/post/1697182/


All Articles