Why is this legal?

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Why is this legal?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:16 pm

by allistar >> Mon, 2 Dec 2002 21:49:40 GMT

Hi there,
I have a class called "Customer". On that class is a method called "doIt" and one called "doIt2". Both of these methods are protected.

In the doIt method in one Customer instance I call the "doIt2" method
for a different Customer instance. The Jade compiler is happy with
that. I don't think this should be legal as I am now calling a
protected method on a different object (granted both objects are of
the same type, but they are seperate instances).

Anyone else think this should be legal? You can also set
protected/read only properties on a different object in the same
fashion.

Regards,
Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Why is this legal?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:16 pm

by JensRichnow >> Tue, 3 Dec 2002 1:42:24 GMT

As far as I understand compilers, a syntactical and semantic checking is done which means only information available at compile time can be processed. This is the difference between compile time and run-time behaviour. At compile time no objects/instances are present. Although you intend to differentiate between objects of the same class with the run-time behaviour in mind, the compiler has no "knowledge" of instances at compile time. Only class type checkings are done.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Why is this legal?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:16 pm

by allistar >> Tue, 3 Dec 2002 2:19:36 GMT

It seems that that is the way it works. The compiler should be able to tell whether you are calling a method on the "self" object or not,
which I would have thought would have been the way protected and read-only accesses were honoured.

Oh well, it doesn't effect me at all - I was just interested in why.

Allistar.

------------------------------------------------------------------
Allistar Melville
Software Developer
Auckland, NEW ZEALAND

Greentree International,
Developer of Greentree Financial Software. ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Why is this legal?

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:16 pm

by cnwjhp1 >> Tue, 3 Dec 2002 6:09:19 GMT

I noticed that also in a recent implementation. I concluded (rightly or wrongly) that it is part of encapsulation - that the class knows what is ok and what is not, that "protected" means protected from other classes, not from other instances of the same class (as they know the rules for the class).

Cheers,
John P


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 9 guests

cron