Запитати

Чим відрізняється екземпляр класу від об'єкта класу?

Вирішено
04 жовтня 2020 · 1.2K ·
0

Чим відрізняється екземпляр класу від об'єкта класу в objective-c? Поставили таке питання на співбесіді, я в подиві відповів "Не розумію питання, хіба це не одне і те ж?". Прохання сильно не штовхати, objective-c вчив сам, в прискореному темпі, і часу розбиратися з самою концепцією не було.

ооп objective-c класи

Відповіді на питання (1)

04 жовтня 2020
0
Обране рішення

У документації по Obj-C використовуються терміни class object і class instance. Якщо їх дослівно перекласти, то вийде якраз те, про що Вас запитували. Причому в українській мові природньо об'єкт класу прийнято вважати його экземпляром. У той час, як очевидно, що означає англійський термін class object - цей об'єкт, в якому зберігається, так би мовити, інформація про клас.

Class Objects A class definition contains various kinds of information, much of it about instances of the class:

The name of the class and its superclass A template describing a set of instance variables The declarations of method names and their return and argument types The method implementations This information is compiled and recorded in data structures made available to the runtime system . The compiler creates just one object, a class object , to represent the class. The class object has access to all the information about the class , which means mainly information about what instances of the class are like . It's able to produce new instances according to the plan put forward in the class definition .

Although a class object keeps the prototype of a class instance , it's not an instance itself . It has no instance variables of its own and it can not perform methods intended for instances of the class . However, a class definition can include methods intended specifically for the class object -class methods as opposed to instance methods. A class object inherits class methods from the classes above it in the hierarchy , just as instances inherit instance methods.


Для відповіді на запитання необхідно авторизуватись

Вхід / Реєстрація