Re: Protected static members, abstract classes, object composition vs. subclassing



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).

For me "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 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.

"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.
It is more tricky because despite argument.callee.caller gives us the
actual caller, we cannot simply ask to caller "Who's your master?"
because the caller has no clue itself at that time ("incontinence of
[this]") 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:

this.foo = /*public*/ function() {};
this.foo.oID = newID;

this.bar = /*private*/ function() {};
this.bar.oID = newID;

and then later in bar:

if (arguments.callee.caller.oID = (arguments.callee.oID) {
// legal call
}
else {
throw new Error("Attempt to access private member out of the object
scope");
}

I'm not saying this is a final solution and in any case it still
doesn't guarantee a buletproof protection as I said in the original
post.

.



Relevant Pages

  • Re: Protected static members, abstract classes, object composition vs. subclassing
    ... Protected is public to some objects and private to others. ... > to public object members. ... Or not, in ECMAScript, where no - caller - property is defined. ... > protection as I said in the original post. ...
    (comp.lang.javascript)
  • Re: dll custom properties
    ... In your application that uses the DLL you create a new instance of "MyClass" ... properties are members of classes that have a lifetime. ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.languages.vb)
  • Re: C# confusion
    ... MyClass" then you will never create an instance of MyClass on the heap, ... so any instance members you declare in MyClass will never exist. ... of memory: not the stack and not the heap, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# confusion
    ... associated with it on the heap (including static variables). ... If you create instances of MyClass, ... static keyword; This one has been hitting me like a hammer on the head. ... Static members are associated with the type itself rather than with any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# confusion
    ... If you create instances of MyClass, ... you are allocating an area of memory for the data segment for each ... data members are initialised upon first reference of the class. ... static keyword; This one has been hitting me like a hammer on the ...
    (microsoft.public.dotnet.languages.csharp)