私たちのビジネスモデルには学生クラスがあります。ある学生を別の学生から操作している場合、学生のプライベートメンバーが表示されます。これはなぜですか?
class Program {
static void Main(string[] args) {
Student s1 = new Student();
Student s2 = new Student();
s1.SeePrivatePropertiesAndFields(s2);
}
}
public class Student {
private String _studentsPrivateField;
public Student() {
_studentsPrivateField = DateTime.Now.Ticks.ToString();
}
public void SeePrivatePropertiesAndFields(Student anotherStudent) {
//this seems like these should be private, even from the same class as it is a different instantiation
Console.WriteLine(anotherStudent._studentsPrivateField);
}
}
これの設計上の考慮事項/意味について考えてもらえますか。兄弟から情報を隠すことはできないようです。フィールドまたはメンバーを同じクラスの他のインスタンスから非表示としてマークする方法はありますか?