moldov
moldov

Reputation: 31

Objective-C difference between class and instance of that class

Could someone explain to me what is the difference between class and instance of the class. If I can use only one instance of the some class in the program, can I use the class like an instance and change all the (-) with (+) in the methods declaration. What is the difference between the class and instance methods. Thanks

Upvotes: 0

Views: 3398

Answers (2)

user326503
user326503

Reputation:

Please visit Cocoa Design Pattern Singleton for single instance of class.

Upvotes: 0

Rafe Kettler
Rafe Kettler

Reputation: 76945

This seems to be several questions:

  1. What is the difference between a class and an instance of a class?
  2. What if I can only use one instance of the class?
  3. What is the difference between class and instance methods?

First, the difference between a class and an instance of a class is that a class is a specification for an instance. The class will always be there, but you must create an instance to use the instance methods of that class. The class is what creates instances and gives them methods.


Second, "if I can use only one instance of a class in a program" is a situation that will never come up. You can make as many instances of a class as you want (hardware permitting).


Third, the difference between a class and an instance method is that while you must create an instance to use an instance method, class methods are just useful functions that the class offers without creating an object from that class. Instance methods operate on the properties/fields of specific instances, while class methods merely accept input and return values independent of any instances.

Upvotes: 1

Related Questions