I would say that the module is closest to a c++ namespace, which itself can 
be thought of as a static class. Note, however, that in both cases you 
can't really have separate instances.

Because of the desire to separate dispatch from type information, Julia 
doesn't really follow the OOP paradigm. You can have a hierarchy of 
abstract types, but abstract types contain no information besides their 
name and place in the hierarchy. Because of multi-dispatch, functions live 
outside of types (i.e., because you can dispatch on all parameters, usually 
no one type owns that function). Finally, you can build an interface to 
mimic an OOP design, but each concrete type still has to re-define the 
variables (which, is one of the biggest advantages of an OOP design). 

One of the really nice things about Julia is that you could in theory 
create a macro to simulate OOP in Julia:

@class foo <: a, b, c
# ...
end

where `@class` creates a new type `foo`, which pulls in the member 
variables of `a`, `b`, and `c` to simulate a mix-in design.

On Sunday, October 18, 2015 at 8:41:58 AM UTC-4, Sisyphuss wrote:
>
> When I'm learning Julia, I am always thinking what is the correct way to 
> do OOP in this language. It seems to me that what I learned in C++ does not 
> apply in Julia.
>
> It took me long to realize that the equivalent of Class of C++ in Julia is 
> not Type, but Module. Module is the basic function unit in Julia.
>
> Thus, a Class in Julia is like
> module ClassName         # class Name {
> using                    #     include<>         // should be outside
> import                   #     include<>
> export  function         #     public  function;
> var = 1                  #     private static var;
> end                      # }
> This provides the same structure as C++.
>
> However, this design has two issues:
> 1) The visit control is not as fine-grained as in C++, the encapsulation 
> is not strict;
> 2) Variables at the top level of a module are global variables.
>
> These two points are closely correlated. If we let module have private 
> variables, then they are not too different from local variables, ans thus 
> can be type inferred.
> I think this is a natural way to do OOP with Julia.
>
>
>
>

Reply via email to