avatar
g*y
1
In Class A, I have several private data memebers,
in one public function of A, I take another object B of type A as parameter.
Why can I access B's private member?
For example
public class A
private a1 as Integer
private b1 as Interger
public sub test(byval B as A)
me.a1 = B.a1
~~~~~~
end sub
End class
avatar
p*n
2
it is probably a BUG in the framework or it is "By Design"

【在 g****y 的大作中提到】
: In Class A, I have several private data memebers,
: in one public function of A, I take another object B of type A as parameter.
: Why can I access B's private member?
: For example
: public class A
: private a1 as Integer
: private b1 as Interger
: public sub test(byval B as A)
: me.a1 = B.a1
: ~~~~~~

avatar
g*y
3
If it is true.
How can you expect the MSIL code of VB.net and C#.net could be the same?
I assume that c# doesn't have such problem.

parameter.

【在 p***n 的大作中提到】
: it is probably a BUG in the framework or it is "By Design"
avatar
d*p
4
It is called class-based "private".
It is true for all c++ family language, including
java and C#. While Smalltalk supports what you
what, object-based "private".
BTW, "protected" is different.

【在 g****y 的大作中提到】
: If it is true.
: How can you expect the MSIL code of VB.net and C#.net could be the same?
: I assume that c# doesn't have such problem.
:
: parameter.

avatar
s*i
5
In C#, you will get the same thing.
I think it is a good thing. By default, the "producer" of class A, who is the
programmer, has all the power to design, implement anything related to A. So
when he is implementing something related to A, he should be able to access
anything.
However, the "consumer", other classes that uses A, should have restricted
access power.
Any senario that this could be a really bad idea?

【在 g****y 的大作中提到】
: If it is true.
: How can you expect the MSIL code of VB.net and C#.net could be the same?
: I assume that c# doesn't have such problem.
:
: parameter.

avatar
g*y
6
en. That means, if I want, I could make the objects of same type access each
other's private member ?
I don't think it is true in C++ or Java.

the

【在 s*i 的大作中提到】
: In C#, you will get the same thing.
: I think it is a good thing. By default, the "producer" of class A, who is the
: programmer, has all the power to design, implement anything related to A. So
: when he is implementing something related to A, he should be able to access
: anything.
: However, the "consumer", other classes that uses A, should have restricted
: access power.
: Any senario that this could be a really bad idea?

avatar
s*i
7
Only when you are writing code within class A{} scope, you can do that. I am
not sure about Java and C++.

So
access

【在 g****y 的大作中提到】
: en. That means, if I want, I could make the objects of same type access each
: other's private member ?
: I don't think it is true in C++ or Java.
:
: the

avatar
g*y
8
en. That means, if I want, I could make the objects of same type access each
other's private member ?
I don't think it is true in C++ or Java.

【在 d******p 的大作中提到】
: It is called class-based "private".
: It is true for all c++ family language, including
: java and C#. While Smalltalk supports what you
: what, object-based "private".
: BTW, "protected" is different.

avatar
g*y
9
Thanks.

each
is
A.
restricted
same?

【在 s*i 的大作中提到】
: Only when you are writing code within class A{} scope, you can do that. I am
: not sure about Java and C++.
:
: So
: access

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。