lua-users home
lua-l archive

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



On Apr 03, 2006, at 21:55, Dolan, Ryanne Thomas (UMR-Student) wrote:

I think this basic idea could be extended and become quite powerful. Any ideas for improving this system? Is there another implementation that is inherently faster or more flexible? Let me know what you think.

Couple of things:

- It would be nice to have the class system tied with Lua's module, so one could import a class directly:

local Vector = require( "Vector" )

- Class definition shouldn't pollute the global name space.

- A class should be flexible, supporting 'mixins' (e.g. adding methods to the class after the class has been defined). Presently you seem to copy the parent(s) methods, preventing any class evolutions.

- Support a bare minimum of reflection (class, className, superclass, etc).

- Support parent method invocation when overwriting an implementation (e.g. super.init( self ) ).

All in all, I personally much prefer Tomas recent proposal which elegantly leverage Lua's built-in module system:

http://lua-users.org/lists/lua-l/2006-03/msg00336.html

Something along these lines:

local function extends( aSuper )
        return function( aClass )
                setmetatable( aClass, aSuper )
                aClass.__index = aClass

                aClass.self = aClass
                aClass.super = aSuper

                return aClass
        end
end

local class = module

class( "Object", extends(), package.seeall )
class( "MyObject", extends( Object ) )

My 2¢.

Cheers

--
PA, Onnay Equitursay
http://alt.textdrive.com/