Re: Protected static members, abstract classes, object composition vs. subclassing
- From: "Richard Cornford" <Richard@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 01:33:37 -0000
VK wrote:
> Richard Cornford wrote:
>> try {
>> var goodBoy = new myClass();
>> goodBoy.messenger('Hi!');
>> }
>> catch(e) {
>> alert(e.message);
>> }
>>
>> try {
>> goodBoy.messenger.call({utils:goodBoy.utils}, 'Hi xxx!');
>> goodBoy.utils.messenger('Hi yyy xxx!');
>> ({messenger:goodBoy.utils.messenger}).messenger('Hi mmm xxx!');
>> }
>> catch(e) {
>> alert(e.message);
>> }
>
> Actually... having read you post once again I'm missing the
> point of your exaltation.
>
> myClassUtils constructor is minded to be "protected" - not
> "private". These are all different categories (depending of
> course of the school).
Protected is public to some (selected) objects and private to others.
With different languages applying different criteria to deciding who can
see what, and when.
> For me
This will be good.
> "protected" means that I cannot obtain an instance of such
> class independently but only as a part of a super-imposed
> class (myClass in this case).
So nothing related to the meaning of the term in any programming
language?
> So I don't see how the use of goodBoy which is a legal
> instance of myClass may prove anything in the concern
> of the "protected" status.
Your protected method could be called with any object as its - this -
object. If the function were a getter it would get for any object, if a
setter it would set for any object, and if it acted it would act for any
object.
> "private" means that a particular member is accessible only
> to the privileged object members - in the most common case
> to public object members. So in the listed case we want to
> make myClass.utils.messenger() to be accessible only to members
> of myClass.
Well, the object design is stupidly elaborated for no reason, but if you
insist.
> It is more tricky because despite argument.callee.caller
> gives us the actual caller,
Or not, in ECMAScript, where no - caller - property is defined.
> we cannot simply ask to caller "Who's your master?"
> because the caller has no clue itself at that time
As there may be no caller it could not be asked anything. But otherwise
this is incoherent.
> ("incontinence of [this]")
This is another manifestations of your general misconception of
javascript. The - this - keyword has well-defined and constantly
implemented meaning, your problems with it stem from your not
understanding javascript and nothing else.
> But you can check against some caller's feature to see if
> it's a valid caller. I left the final solution open so the
> relevant block is commented out. The first idea would be to
> use Java's object id-stamping. Thus each new instance get's
> an unique ID and you stamp all members which this ID:
Unnecessary as objects have distinct identity that can be verified.
> this.foo = /*public*/ function() {};
> this.foo.oID = newID;
>
> this.bar = /*private*/ function() {};
> this.bar.oID = newID;
You silly sod. Verification with a shared secret, and then making the
secret a public property of the objects so that it is not secret at all.
What a waste of effort! If you cannot apply better analysis to the
problem than this you are wasting everyone's time commenting on the
subject at all (although that goes for the vast majority of your posts
anyway).
> and then later in bar:
>
> if (arguments.callee.caller.oID = (arguments.callee.oID) {
^ ^
An assignment operator instead of comparison and unbalanced parenthesise
making this a syntax error?
> // legal call
> }
> else {
> throw new Error("Attempt to access private member out of the object
> scope");
> }
OK. That is actually less effective than your first attempt (even if the
errors were corrected).
> I'm not saying this is a final solution
I don't know, if your problem is only convincing people who don't know
any better this will do as well as the first.
> and in any case it still doesn't guarantee a buletproof
> protection as I said in the original post.
No, it isn't. But the question is not whether you are incapable of
implementing an effective emulation of 'protected' (in some meaningful
sense of the term) in javascript (obviously that if far beyond you), but
rather whether it can be done.
Having determined whether or not it can be done it becomes possible to
give an informed consideration as to whether it should be done (would
the overheads and authoring effort be justified by the result?). But
holding up a sequence of hollow imitations of some form of 'protection'
do not contribute at all to an understanding of the subject.
Richard.
.
- References:
- Protected static members, abstract classes, object composition vs. subclassing
- From: Kevin Prichard
- Re: Protected static members, abstract classes, object composition vs. subclassing
- From: VK
- Re: Protected static members, abstract classes, object composition vs. subclassing
- From: Richard Cornford
- Re: Protected static members, abstract classes, object composition vs. subclassing
- From: VK
- Protected static members, abstract classes, object composition vs. subclassing
- Prev by Date: Re: Help with a slide show
- Next by Date: Re: Protected static members, abstract classes, object composition vs. subclassing
- Previous by thread: Re: Protected static members, abstract classes, object composition vs. subclassing
- Next by thread: Re: Protected static members, abstract classes, object composition vs. subclassing
- Index(es):
Relevant Pages
|