spekary / gopp

A go preprocessor that adds some object-oriented shortcuts to the language.
MIT License
1 stars 0 forks source link

Automate getter and setter creation #2

Open spekary opened 8 years ago

spekary commented 8 years ago

Since an object is only accessed through its interface, there is no inherent way to access member variables from outside the object. We need getters and setters.

We can assume that if a member begins with a capital letter, we want getters and setters on it, as if it were public. Lower case means no getters or setters. It can also be controlled further with a struct tag (which would need to be parsed to be used.)

M1 string `gs:"out"`
M2 int 
m3 int 
m4 float64

The getters and setters would be idiomatic go, in that getters are just the Capitalized name of the member, and setters use the initial "Set" word. As in:

func M1() {
    return this.M1
}

func M2(){
    return this.M2
}

func SetM2(M2 int) {
    this.M2 = M2
}

Would be generated for the above.