[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Abstract classes and interfaces in Lua
- From: luciano de souza <luchyanus@...>
- Date: Fri, 14 Apr 2017 14:34:18 -0300
Andrew,
If interfaces doesn't make sense in Lua, so I really can follow another way.
Actually, I feel myself a little bit lost. In other languages, we can
find many references talking about OOP, abstract classes, interfaces,
dependence injection...
With the GOF design patterns, we can assimilate several conceptual
structures and apply it.
The problem is that Lua is so different that I am not able to
understand whats the best practices.
Does we have example of design patterns in Lua? Does GOF patterns make
sense in Lua?
The reason I am using Penlight as an OOP module, even though the
metaprograming features, indicates that I am not confortable with this
lack of references.
Penlight is a very good library and allows me to think as I thought
before Lua. In the future, perhaps my mind changes, but the truth is
that Penlight allows me not to change everything.
Using Penlight, I can implement Visitor, Strategy, Abstract Factory...
If this is not natural for LUa, what's is natural? How can I find
models to follow?
2017-04-14 13:50 GMT-03:00, Andrew Starks <andrew@starksfam.org>:
> 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
> obj.interfaces.foo 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.
>
> -Andrew
> On Fri, Apr 14, 2017 at 10:22 luciano de souza <luchyanus@gmail.com> 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
>> interfaces.
>> 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
>>
>>
>
--
Luciano de Souza