Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class methods and instance methods - when/when not to use them?

I was wondering when and when not to use class methods and instance methods. I need some practical examples. I am really confused. Another question: can't we do exactly the same things with instance methods that we can with class methods?

like image 871
Tushar Chutani Avatar asked Jan 17 '26 01:01

Tushar Chutani


1 Answers

Class methods: The method isn't tied to any specific object. In a way it acts like a free function in the class's namespace. No 'self' pointer. For instance [UIScreen mainScreen] is a class method because there's only one screen and there's no need to care about multiple 'screen instances'.

Instance method: Tied to a specific object.

This applies to most OO languages, not just obj-C.

like image 55
seand Avatar answered Jan 19 '26 16:01

seand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!