Is Class an object or a structure?

Is Class object or a structure?

+4
source share
5 answers

Objective-C classes are treated as objects with several restrictions (see Objective-C Programming Language ):

Class objects, therefore, are full-fledged objects that can be dynamically typed, receive messages, and inherit methods from other classes. Special only is that theyre created by the compiler, the lack of data structures (instance variables) other than those that are built from the definition class and are agents for producing instances at runtime.

Behind the scene, a class definition contains various types of information, most of which apply to class instances:

  • Class name and its superclass
  • Template describing a set of instance variables
  • Method name declarations and their return types and arguments
  • Method implementations
+5
source

Officially, it is implemented as a structure, but the Objective-C runtime allows you to consider a class as an object. Cocoa lovingly has a great article on how classes and metaclasses work in Objective-C .

+5
source

Class types are reference types, and struct types are value types. Instances of classes or structure types are called objects.

+1
source

Class is a type that can hold a pointer to a class object (similar to how id is a type that can hold a pointer to any object). Class is not a class name (just as id not a class name). A class of a class object is a metaclass of this class (not included in it). Class objects are first-class objects; and you can do the same with them as regular objects. A method call of a class object calls a class method in this class (or some class of the ancestor); you can also call instance methods of the root class of the class on the class object.

0
source

Not. A class is not an object because the object is an instance of the class. Objects are derived from a class, so we cannot say that a class is an object.

If we consider the whole class as an object for another class, we still cannot call it an object . Because, as soon as we create a class, it will be a Class until it is deleted.

You can also find the answer to this question in this link. Are Java class objects?

-1
source

Source: https://habr.com/ru/post/1312846/


All Articles