All the docs I've read mention how to access data thru public static methods annotated with @AuraEnabled but is it possible to access public variables defined in the server controller like we can in visualforce pages?
Actually, neither Visualforce nor Lightning components allows access from the page/component context to variables in an Apex controller.
Lightning Components allows access purely through methods exposed as at least public, and annotated as
@AuraEnabled. Remember that LCF has no feature that is directly executed on the server side. So if you want to surface it, you need to write a method.
Visualforce gives several options:
- Getter/setter methods
- RemoteAction annotated methods
But technically speaking, none of these are variables in the strictest sense.
I suspect the confusion comes from the fact that properties might look like variables syntactically, but the way I think of properties is as a special syntactic convention for creating getter and setter methods (although there may be more to it than that).
In making this distinction, I primarily rely on the difference that variables store some kind of value, and methods contain one or more instructions to execute logic.