lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>What do you mean by "putting OOP in the core"?
Having native support to OOP in Lua:

class A
	function A(name)
		self.name = name
	end
end

class B extends A
	function B(name)
		super(name)
	end

	function toString()
		return name
	end
end

b = new B('me')
print(b.toString())

>
>Lua already has the polymorphism aspect of OOP fairly well handled.
Yes.

>
>Inheritance is handled fairly cleanly in most of the OOP implementations for
>Lua so long as you don't want to make calls up the inheritance chain (i.e.,
>you don't care about super). Super calls can be handled just like in C++ and
>Python and those pass OOP muster with at least some people, so even this may
>be a non-issue.
Inheritance is what separates structures from classes. You can declare a structure, alloc an instance of it in memory and do things like obj->toString(obj).

>
>Encapsulation is complicated to achieve. There are work arounds (I posted
>one to the Wiki this morning), but none of them are perfect. But
>encapsulation is arguably more about modularity than it is about OOP. For
>example, my ideal answer to encapsulation would probably be to introduce
>some form of private key declarations within modules together with ways to
>keep them private.
I agree it's more about modularity, but it's important in OOP to hide the implementation of the class and, most important, keep users out of trouble. Just telling them to not touch some properties is not enough in my opinion.

>
>Mark

Andre de Leiradella