Instance methods, static methods, class methods

From Helpful
Revision as of 01:40, 18 February 2024 by Helpful (talk | contribs) (Created page with "<!-- For context, most functions defined on a class will be considered '''instance methods''': they will work on an instance of that same class. Calling them will always take. (exactly how explicitly it is in the ''definition'' of this function may vary with the language) They will accept one, and do so implicitly somehow - some languages make you write out the object reference ('self' or 'this' turns up around here), others have it implied. That is not the only...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


  • class methods are defined on a class, and do not take an instance, but do get a reference to that class, meaning they can fetch class variables (note: not instance variables)
...and could potentially alter that class
...but more frequently seem used for things like factories?(verify)
from the context of instqance variables, self.__class__ often lets you cheat you way out of needing these (but it's not as clean)
Not used much unless you do some meta-modelling, or need a reference to the class but not an instance.

\ -->