lua-users home
lua-l archive

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

I've never been able to reason about the value or utility of most patterns, within the context of Lua, which is a dynamic language.

For example: my understanding is that interfaces are a way to say that a particular object has all of the methods and properties that are defined by an interface. In a dynamic language, you can simply say that it does (if then) and then support those methods---if you don't it won't work so you need to test.

Building up checks for compliance on a language level is probably possible (to some degree less than 100%), but it doesn't jive with Lua, in my experience. In order to enforce enough limitations to make such a concept useful, you have to build up type checking, etc. Eventually there is a point where the complexity and performance trade offs lead me to understand why such a thing didn't exist in the first place.

That is, whenever I found myself meta-programming in Lua, I end up throwing it away.

My .02 cents. I suspect that you won't find this helpful, but I've tried to implement interfaces before and your question reminded me of that experience.

On Fri, Apr 14, 2017 at 10:22 luciano de souza <> wrote:
Hello all,
Dispite of the fact Lua is not a object oriented language, by means of
modules like Penlight, we have support.
However, some design patterns like Strategy, Abstract Factory or
Visitor demands, as far as I able to know, abstract classes or
So my question is: is there Lua implementations for abstract classes
or interfaces?
More broadly, I ask: does someone know examples of design pattern
implementation in Lua?
Best regards,

Luciano de Souza