Re: middleclass & middleclass-extras: OOP for LUA
Posted: Mon Nov 29, 2010 9:39 pm
Then that's fine. As long as colour is always spelled with a u, there's no problem.zac352 wrote:I'm consistent.
Then that's fine. As long as colour is always spelled with a u, there's no problem.zac352 wrote:I'm consistent.
Well, I don't like that idea because someone could say "hey, it should also include iniciar and intialisieren". Once you accept 2 languages, what stops you from accepting several more? You have do draw the line somewhere.Jasoco wrote:It should accept both spellings as correct. That's the way it should be. Color, colour, doesn't matter.
Code: Select all
function Object.initialise(...)
Object.initialize(...)
end
Code: Select all
require 'middleclass' -- or similar
require 'middleclass-extras.init' -- or 'middleclass-extras'
MyClass = class('MyClass'):include(Indexable)
function MyClass:initialize(a,b,c)
super.initialize(self)
self.a, self.b, self.c = a,b,c
end
function MyClass:index(name) -- attention! index, not __index !
return 'could not find ' .. tostring(name)
end
local x = MyClass:new(1,2,3)
print(x.a) -- 1
print(x.b) -- 2
print(x.c) -- 3
print(x.d) -- 'could not find d'
Code: Select all
super.initialize(self, foo, bar, baz)
Code: Select all
self.super:initialize(foo, bar, baz) -- I still have to iron out some details, though
In other languages that are at least similarish to Java (like ActionScript, and C++) you can have abstract base classes (Java has these as well I think) to fix the problem; but they're only in the line of single inheritance. I think the perfect mix is having single inheritance, mixins, and the possibility of abstract mixins and base classes; that would be sweeeet.kikito wrote:"why can't I just have a default implementation???"