Method

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

A method is a special attribute of an object that is callable. It has the following characteristics.

  • Like a function, it has parameters and a return type.
  • However, when called, the self / this (assumed or explicit) is set to the object it was accessed from.

Some languages like Java dictate that practically everything you do needs to be handled with methods.

Some people prefer methods to attributes because you can intercept the access and setting of an attribute if they call methods to do these things. I like languages like Python that allow you to set hooks to intercept attribute access and sets to do interesting things.

See Also