lua-users home
lua-l archive

Re: advice needed: OO style

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


On 27/04/2011 21.55, Javier Guerra Giraldez wrote:
On Wed, Apr 27, 2011 at 2:29 PM, Lorenzo Donati
<lorenzodonatibz@interfree.it> wrote:
- the actual object is stored in the proxy table using a "private" index
(the metatable itself) to achieve encapsulation and prevent the client from
tampering with the object directly.
as i understand it, encapsulation means having all relevant state
within the same object. what you describe here is access control.
Fair enough. I just was way too sloppy with terminology (and probably too much emphatic when speaking of "tampering") :-P I really meant "data hiding". As for access control, I don't care really much about it (I don't need sandboxing or to operate with strict security constraints). I just want to make sure (cheaply - without too much coding) that the client won't accidentally overwrite a field or a method of my objects and to ensure that objects are opaque, just to better support the abstraction they represent. I like clean interfaces!
IMHO, encapsulation is great for clean code; access control is
overrated. (note that Python doesn't have it and they claim it to be
a 'clean', 'readable', language)
I agree on access control. As for Python, I used it for too short a time to make a meaningful comparison (never got to the point to learn its OO feature - when I was about to, I stumbled into Lua! :-D )
Note: I don't need inheritance support, since almost always use this pattern
to represent objects of "concrete classes".
hurray!
:-D
--
Lorenzo

AltStyle によって変換されたページ (->オリジナル) /