I think I am not talking about the same thing with you guys. In my
definition, the difference of single/multiple dispatch has nothing to do
with what I am talking. What I talked about is just a suitable way
for encapsulation.
For example, the example code can include a type and multiple dispatch
function in the module
module ClassName # class Name {
using # include<> // should be
outside
import # include<>
type TypeName
export TypeName, fun # public fun;
var = 1 # private static var;
function fun(obj::TypeName, arg)
end # }
In single dispatch, a class defines an object and its properties and
behaviors.
In multi dispatch, a module defines a type and the functions which
recognize it.
On Sunday, October 18, 2015 at 2:41:58 PM UTC+2, 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.
>
>
>
>