Interested in OOP Classes with private/public access?

Hi folks!

I’m working on a module to assist with object oriented programming in luau. I’m currently implementing private / public (and maybe protected) access specifiers, and I’m trying to gauge interest in those features. Would access specifiers be useful to you? Would love to know your thoughts!

For those who don’t know, access specifiers are a feature of other languages (I’m taking inspiration from C++) which mean that you can only access certain keys of a table from certain places in your code. For example, if I had a SecretKeeper class that had a private member called ‘secret’, trying to access this from outside the class would throw an error. However, I could implement a ‘getSecret’ method, which would return the secret to pieces of code outside the class. Because the method is a member of the class, it has access to the class’s private members.

Access specifiers are useful for putting together large projects, as they help ensure that your class can only change in the ways you specify it can change. They also help encapsulate information so derived classes don’t have access to internal workings of higher-up processes.

So yeah, would you use this feature in your development? Cheers!

6 Likes

This is specific and not general please re-post or move to #help-and-feedback:scripting-support

2 Likes

Thanks for the heads up :slight_smile: Wasn’t sure exactly where to put this so I appreciate the advice

1 Like

I’ve made a resource similar to this a while back. Feel free to check it if you’re interested!
Class | Supercharge your classes - Resources / Community Resources - Developer Forum | Roblox

On the main point, honestly, I don’t think access specifiers would bring too much of an impact since we have type-checking already—which where we can just return the custom type without the private variables. However, I’d like a small quality of life feature if we really want to make metatables strict!

1 Like

Cool resource - looks very full-featured! Will definitely reference that as I work on the implementation :slight_smile:

1 Like