Do the words to, as and get have any special meaning when used in method names?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
as is often used to denote that the method casts the item from one type to another, without creating a new object.
to often indicates that the method creates a new representation of the value as a new object of a different type.
get, along with
set in Java EE has a special meaning as getters and setters, which are simply access and modify methods respectively to a private field. However, there does sometimes exist the convention in a wider sense of
get indicating an existing value is returned and
create indicates a new value is created.
And then there are many many situations where none of the above applies and
as is used to create new objects,
to just does a cast,
get creates something etc.
get in the Java EE context, the answer to "do the words to, as and get have any special meaning when used in method names?", the answer is "sometimes".
According to naming conventions, prefix of any variable/method name/class name should like in such a way so that it automatically describes its usage.
You should use as keyword as a prefix in the method name when you want to convert particular object or variable of specific type of data into the other type if data. i.e. type casting.
You should use to keyword as a prefix in the method name when you want to show an object or variable in the different type without converting it from its original datatype.
You should use get keyword as a prefix in the method name either it is a get method from getter / setter or else you are retrieving data from the database.