Lesson 8
Making Objects the Main Star!
Chapter 6: Object methods
Methods and attributes
You have probably figured this out by now - you can define your own methods for your own class.
Methods are often actions, so like functions, they will often end up being verbs. For example, a person can speak, walk, run, study, or cry.
In object-oriented programming, attributes represent an object’s state or properties (what an object has), while methods model the object’s behaviour (what an object can do).
An object’s method is bound to the object itself. Object methods have access to the object’s own attributes or states, and can even modify its state (think mutator methods like list.append()
). In short, an object’s states and attributes are now ‘in sync’, and acts as a single coherent unit!