Conversation started Feb 26, 2020 at 16:04.
Feb 26, 2020 16:04
@MathieuGuindon I just realized a question about VBA design. Would you agree that if you have a class that has no state, does it really want to be just a module?
@this yeah, but I don't want to tell a tale of any sort, temp or otherwise...
@this I asked that (not in so many words) a few days ago. Never got a response from the class...
@FreeMan Sorry missed that. My guts says that if there's no state, there's no need for instance, and instancing is a new complexity.
I'm sure you can have classes with no internal data. An example would be to receive or to fire events. But that's not what I am thinking of having a state.
@this in theory, yes - it's basically a static class. In practice, its members are now exposed as macros and UDFs, and if I don't want that, even with Option Private Module (which merely hides the members from view, but they can still be invoked)
WTF
that's pretty much what I thought, but... Mug's code review appears to me to have a stateless class
Feb 26, 2020 16:10
Yep, that's one
If the class implements an interface, it really does not want to be a module.
It is basically a strategy.
Thinking about it - the Option Private Module prevents access from outside the project but not within. The host has the project so I guess it's "within". :\
I write tons of such classes.
In this case, there's no interfaces involved, but you're correct that if I find it needing an interface, then I'd have to convert it to a class proper
In which case such conversion is trivial.
Feb 26, 2020 16:11
At least, with Option Private Module the procedures do not appear in the selection in the macros window.
(converting class to module is not always trivial, though)
@M.Doerner yeah but if you know the name you can just type it in ...and it runs
..which makes Option Private Module marginally useful IMO
Confirmed the same behavior in Access
So it's really only good for blocking other projects from calling the function.
also, isn't a module just a crippled class?
I don't think so.
at low level, there are no classes.
Feb 26, 2020 16:15
oh
I had it the other way around
@MathieuGuindon What did you expect in Excel? After all, you can invoke private methods there.
Classes only hide the fact that we are doing stuff like someClass::someMethod(someClass* self, ...);
@this good point
VBA, being a bit older shows more of the C/C++ "root" than Java or C# does.
 
Conversation ended Feb 26, 2020 at 16:16.