Question: is it possible to have inner module inside object and have these logically be part of the object?

This is the problem: My object is getting large with many private methods.

In non-OOP setup, I could make different modules A,B,C and put relevent methods inside each module.

Now I find I can not do this inside the object. All methods have to be flat and at same level. So I lose the benefit of using different name space for different methods.

It will be easier to explain with a simple example. Lets say I have this now

restart;

A:=module() 
    option object; 
    local name::string:="";  

    export ModuleCopy::static:= proc( self, proto, name::string, $)          
         self:-name := name;
    end proc;

    export process_1::static:=proc(_self,$)
       _self:-process_2();
    end proc;

    local process_2::static:=proc(_self,$)
       print("in process_2 ",_self:-name);
    end proc;

end module; 

The above works by having all methods at same level. I can now do 

o:=Object(A,"me");
o:-process_1()

                  "in process_2 ", "me"

But now as the number of private methods increases I want to put a name space around collection of these for better orgnization, but keep all methods logically as part of the object as before.

I change the above to be

restart;

A:=module() 
    option object; 
    local name::string:="";  

    export ModuleCopy::static:= proc( self, proto, name::string, $)          
         self:-name := name;
    end proc;

    export process_1::static:=proc(_self,$)
       o:-B:-process_2();
    end proc;
    
    #method process_2 is now inside a module. 
    local B::static:=module()
       export process_2::static:=proc(_self,$)
           print("in B:-process_2 ",_self:-name);
       end proc;
    end module;

end module; 

Now

o:=Object(A,"me");
o:-process_1()

Gives an error

Error, (in unknown) invalid input: process_2 uses a 1st argument, _self, which is missing

I tried many different combinations, but nothing works.

So right now I have all methods flat. All at same level. But I do not like this setup. Since I lose the nice modular orgnization I had with using different modules with different methods inside different modules.  

Is there a way to have a module inside an object and call its methods from inside the object as if these method were part of the object private method with only differece is adding the module name in between?

So instead of _self:-foo()  I just change it to  _self:-B:-foo() and have both behave the same way?

In C++, one can use what is called a friend class to do this. 

Please Wait...