QamoosTech
Programming FundamentalsObject-oriented programmingBeginner

Method

PronunciationMETH-ud

Definition

A function that is associated with an object or class, defining the behaviors or actions that the object can perform.

Where you hear it

In object-oriented programming, when defining what an object can do, or when calling a function on an instance.

Examples

  • The user object has a save method to persist its data to the database.
  • We added a helper method to calculate the total price of the cart items.
  • The cart object has a total method that returns the sum of its items.

Common mistake

Calling any function a method, even when it is written outside of any class or object context.

Don't confuse with

Method vs function: A function is a standalone block of code, whereas a method is a function that is bound to an object or a class.

Say it at work

  • In a meeting or chatI think we should move this logic into a private method to keep the class clean.
  • In an email or ticketPlease ensure that the new method includes proper error handling before merging the pull request.