Skip to content

Instantly share code, notes, and snippets.

@gonza7aav
Last active August 23, 2021 22:20
Show Gist options
  • Save gonza7aav/e3c90025a2ae846ef3a4a8ee1c8cd903 to your computer and use it in GitHub Desktop.
Save gonza7aav/e3c90025a2ae846ef3a4a8ee1c8cd903 to your computer and use it in GitHub Desktop.
A VS Code snippet to create the getters and setters for a variable
"Encapsulation principle": {
"prefix": ["encapsulation", "getter", "setter", "private"],
"body": [
"private ${1:type} ${2:variable};",
"",
"private void ${2/(.*)/set${1:/capitalize}/} (${1:type} _${2:variable}) {",
"\tthis.${2:variable} = _${2:variable};",
"}",
"",
"public ${1:type} ${2/(.*)/get${1:/capitalize}/} () {",
"\treturn this.${2:variable};",
"}"
],
"description": "Define a variable with its respective setter and getter"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment