Efficient Object Oriented Programming Tutorial

Is there a way to get this to work with intellisense? Intellisense works up until we start getting into the advanced part of the tutorial where we enable the possibility of inheritance, then it just stops detecting anything :<

1 Like

Thank you for this resource, It was a very interesting read!

1 Like

The way I’ve got around the issue of intellisense, is to define object types within each class module script and exporting them so those types can be used outside of the module script. Types can use the concept of inheritance too! When I create an object, I specify that the variable is of the object type found in the class module script.

I’ve actual developed a pattern of how I develop classes using this system now. In short, I first define the type of the object (the properties and functions). Then I write the class and its logic following the type I created.

The only issue with this is if you don’t keep the type up to date with what’s actually in the class, the mismatch can be confusing and can lead to errors.

Yeahh I should’ve specified if it was possible to do typeof() on the class modules and not having to set up manual types, but it makes sense that we would have to manually create the types.

1 Like

inheritance is a generally bad way to structure your code IMO. I’d recommend to switch to something like an ECS. The type definitions can be pretty annoying to see and write and separating everything into components is preferable.

1 Like

I’m still an avid defender of the OOP paradigm. I know it seems to be pretty popular to hate on OOP nowadays, but there’s definitely still a reason for its existence, plus inheritance is very useful if used correctly, avoiding deep inheritance. OOP is great for organizing code, so I think it works great for large games.

The ECS pattern can get pretty complex when you have a large number of components that all interact with each other though systems. And lua devs tend to implement ECS in a way that removes all of the efficiency gains it’s known for.

In the end, code in whatever pattern / paradigm that makes the most sense for you. But don’t be afraid to learning new patterns / paradigms as well, you might find one that works better for you! My mind thinks in an OOP way, so I usually use OOP in my games.

I’m currently developing an OOP based Archetype ECS system in Lua, trying to tie in some of the benefits of ECS and OOP together. It’s a fun project!

1 Like

yeah I fully understand that, I still use OOP too, It’s very convenient for small independent objects, I just prefer ECS for games as a whole, you can also use composition in OOP instead of inheritance. As you said, to each their own.

2 Likes

Maybe I do not understand as well as I thought, but in the Utility script, RunService:IsClient() would never run if this is in Server Storage or ServerScriptService. Unless I am missing something? And if it works, how do I access that over the client, without moving the script to ReplicatedStorage?

You are completely right.

I typically store Rcade in replicated storage. I keep all generic classes and client-only classes I make within Rcade. Any game specific server-only classes I make I store in a separate folder in server storage.

Things in Replicated storage can be accessed by both server and client, but of course you don’t want to store everything there otherwise all your game logic would be exposed. So, separating and hiding the important server only classes in server storage is what I do to protect my code.

I don’t mind if hackers can access the client only stuff, because usually without the server classes they don’t work as intended and can’t recreate the game just from them.

Though when I was first working with this and ran into this issue, I actually created two different Rcade modules, one for client and one for server. But that got too confusing for me.

Unfortunately, probably not the answer you hoped for, but I still hope this helps!

Oh no, that is exactly what I was looking for, I just wanted confirmation. I am trying this Class layer for the first time and I wanted to ensure I was using it properly. I moved my Class layer from ServerScriptStorage to ReplicatedStorage because that was the only thing I could think of to access it from the Client side. I didn’t wanna make another one for Client since that would probably break DRY anyway, and when I thought about the Class layer being in ReplicatedStorage, I couldn’t think of an edge-case that would allow hackers to use it since my server classes and objects are hidden in ServerScriptStorage so all they would have is a meaningless container.

1 Like