By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,784 Members | 3,582 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,784 IT Pros & Developers. It's quick & easy.

class-based access control VS instance-based access control

P: n/a
xz
Why C++ (as well as Java) adopts class-based access control instead of
instance-based access control?

I had never paid attention to whether an access-control is class-based
or instance-based but only intuitively thought that the latter was the
one being used.

Since it does not seem to make sense to let an instance "a1" of Class
"A" to have access to the private data of instance "a2" of the same
Class A, does it?
Jan 7 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
xz wrote:
Why C++ (as well as Java) adopts class-based access control instead of
instance-based access control?
Mostly because of the different purpose of those. Class-based has the
purpose to prevent coding mistakes, whereas instance-based looks like
a security measure. C++ wasn't designed with security in mind.
I had never paid attention to whether an access-control is class-based
or instance-based but only intuitively thought that the latter was the
one being used.

Since it does not seem to make sense to let an instance "a1" of Class
"A" to have access to the private data of instance "a2" of the same
Class A, does it?
That's an incomplete statement. Since it doesn't, then what? What
conclusion do you expect to derive from "since it doesn't make sense"?
And think of the fact that it doesn't make sense to you, but obviously
makes a lot of sense to millions of other C++ programmers who never
complain about that feature. What does it say?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #2

P: n/a
xz
On Jan 7, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xz wrote:
Why C++ (as well as Java) adopts class-based access control instead of
instance-based access control?
Thanks for you reply.
Mostly because of the different purpose of those. Class-based has the
purpose to prevent coding mistakes, whereas instance-based looks like
a security measure. C++ wasn't designed with security in mind.
I thought the access control was designed in the purpose for
security......
And it is obviously a danger to let "a1" (of class A) to have access
to the private data of "a2".
If you wanna control the privileges of accesses from the outside
world, it's straightforward that any access from outside should be
controlled, whether it is from an instance of different class or the
same class.
Well, but you said class-based is not for security......
I had never paid attention to whether an access-control is class-based
or instance-based but only intuitively thought that the latter was the
one being used.
Since it does not seem to make sense to let an instance "a1" of Class
"A" to have access to the private data of instance "a2" of the same
Class A, does it?

That's an incomplete statement. Since it doesn't, then what? What
conclusion do you expect to derive from "since it doesn't make sense"?
And think of the fact that it doesn't make sense to you, but obviously
makes a lot of sense to millions of other C++ programmers who never
complain about that feature. What does it say?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #3

P: n/a
xz
On Jan 7, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xz wrote:
Why C++ (as well as Java) adopts class-based access control instead of
instance-based access control?

Mostly because of the different purpose of those. Class-based has the
purpose to prevent coding mistakes, whereas instance-based looks like
a security measure. C++ wasn't designed with security in mind.
Then how about Java?
>
I had never paid attention to whether an access-control is class-based
or instance-based but only intuitively thought that the latter was the
one being used.
Since it does not seem to make sense to let an instance "a1" of Class
"A" to have access to the private data of instance "a2" of the same
Class A, does it?

That's an incomplete statement. Since it doesn't, then what? What
conclusion do you expect to derive from "since it doesn't make sense"?
And think of the fact that it doesn't make sense to you, but obviously
makes a lot of sense to millions of other C++ programmers who never
complain about that feature. What does it say?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #4

P: n/a
xz wrote:
On Jan 7, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>xz wrote:
>>Why C++ (as well as Java) adopts class-based access control instead
of instance-based access control?

Mostly because of the different purpose of those. Class-based has
the purpose to prevent coding mistakes, whereas instance-based looks
like a security measure. C++ wasn't designed with security in mind.
Then how about Java?
No, thanks.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #5

P: n/a
xz
On Jan 7, 3:10 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xz wrote:
On Jan 7, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xz wrote:
Why C++ (as well as Java) adopts class-based access control instead
of instance-based access control?
Mostly because of the different purpose of those. Class-based has
the purpose to prevent coding mistakes, whereas instance-based looks
like a security measure. C++ wasn't designed with security in mind.
Then how about Java?
No, thanks.
So you are a fan of tea? :)

OK, let's ask it seriously.
I think Java (the programming language provided by Sun, which is a
company instead of the shining sun in the sky) was designed "with
security in mind", then why Java's access control is also class-based
instead of instance-based?
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #6

P: n/a
xz wrote:
On Jan 7, 3:10 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>xz wrote:
>>On Jan 7, 2:29 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
xz wrote:
Why C++ (as well as Java) adopts class-based access control
instead of instance-based access control?
>>>Mostly because of the different purpose of those. Class-based has
the purpose to prevent coding mistakes, whereas instance-based
looks like a security measure. C++ wasn't designed with security
in mind. Then how about Java?
>No, thanks.
So you are a fan of tea? :)

OK, let's ask it seriously.
I think Java (the programming language provided by Sun, which is a
company instead of the shining sun in the sky) was designed "with
security in mind", then why Java's access control is also class-based
instead of instance-based?
Why are you asking about Java in a C++ newsgroup? The only answer
to your question here is "who cares?"

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 7 '08 #7

P: n/a
xz wrote:
>
And it is obviously a danger to let "a1" (of class A)
to have access to the private data of "a2".
Try to write a copy ctor and assignment operator for your class A.

Probably, access to the private data of object of the same class can
be disabled by default, and a kind of static_cast<will exist to
explicitly change type of reference to enabled.

But what the errors and where have you met already with the access is
enabled by default?

Maksim A. Polyanin
old page about some C++ improvements:
http://grizlyk1.narod.ru/cpp_new
Jan 8 '08 #8

P: n/a
On Jan 7, 8:58 pm, xz <zhang.xi...@gmail.comwrote:
Why C++ (as well as Java) adopts class-based access control instead of
instance-based access control?
Because you couldn't implement copy construction otherwise. If
a language supports value semantics for user defined types, it
pretty much has to use class based access control.
I had never paid attention to whether an access-control is
class-based or instance-based but only intuitively thought
that the latter was the one being used.
Since it does not seem to make sense to let an instance "a1"
of Class "A" to have access to the private data of instance
"a2" of the same Class A, does it?
And how do you implement a copy constructor otherwise?

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jan 8 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.