[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some ways to get encapsulation in Lua
- From: Mark Hamburg <mhamburg@...>
- Date: Wed, 26 Jan 2005 08:52:25 -0800
on 1/26/05 3:12 AM, PA at email@example.com wrote:
> On Jan 26, 2005, at 03:16, Mark Hamburg wrote:
>>> Would the above scheme provide both inheritance and encapsulation
>>> without too much fuss?
>> Yes, but at a fairly high cost per object since every method has to be
>> instantiated and stored into the public table.
> Hmmm... I thought that "instantiation" was one of the tenet of OOP?
> But as long as the price is right...
Well, yes, instantiation is a basic tenet of OOP, but there are multiple
ways to implement things and instantiating every method of an instance is
expensive in terms of both memory and time to construct an object. It does,
however, lead to objects that run fast since there is no __index table
lookup when looking for methods and using closure variables can avoid other
table lookups (again at an expense in memory usage).