What is the difference between class and instance methods?

后端 未结 18 2169
说谎
说谎 2020-11-21 11:55

What\'s the difference between a class method and an instance method?

Are instance methods the accessors (getters and setters) while class methods are pretty much ev

18条回答
  •  执念已碎
    2020-11-21 12:59

    The answer to your question is not specific to objective-c, however in different languages, Class methods may be called static methods.

    The difference between class methods and instance methods are

    Class methods

    • Operate on Class variables (they can not access instance variables)
    • Do not require an object to be instantiated to be applied
    • Sometimes can be a code smell (some people who are new to OOP use as a crutch to do Structured Programming in an OO enviroment)

    Instance methods

    • Operate on instances variables and class variables
    • Must have an instanciated object to operate on

提交回复
热议问题