Objective-C基础之面向对象编程(OOP)——有关术语

0x01 有关OOP的术语


类(Class)

类是一种表示对象类型的结构体。对象通过它的类来获取自身的各种信息,尤其是执行每个操作需要运行的代码。建议开发人员在用Objective-C编程时采用首字母大写的类名。

class is a structure that represents an object’s type. An object refers to its class to get various information about itself, particularly what code to run to handle each action. Simple programs might have a handful of classes; moderately complex ones will have a couple of dozen. Objective-C style encourages developers to capitalize class names. 


对象(Object)

对象是一种包含值和指向其类的隐藏指针的结构体。运行中的程序通常都包含成百上千个对象。指向对象的变量通常不需要首字母大写。

Anobject is structure containing values and a hidden pointer to its class. Running programs typically have hundreds or thousands of objects. Objective-C variables that refer to objects are typically not capitalized.


实例(Instance)

实例是对对象的另一种称呼。如circle对象可以称为Circle类的实例。

Instance is another word for “object.” For example, a circle object can also be called an instance of class Circle.


消息(Message)

消息是对象可以执行的操作,用于通知对象去做什么。对象接收到消息后,将查询相应的类,以便找到正确的代码运行。

message is an action that an object can perform. This is what you send to an object to tell it to do something. In the [shape draw] code, the draw message is sent to the shape object to tell it to draw itself. When an object receives a message, its class is consulted to find the proper code to run.


方法(Method)

方法是为了响应消息而运行的代码。根据对象的类,消息可以调用不同的方法。

method is code that runs in response to a message. A message, such as draw, can invoke different methods depending on the class of the object.


方法调度(Method Dispatcher)

方法调度是Objective-C使用的一种机制,用于推测执行什么方法以相应某个特定的消息。

The method dispatcher is the mechanism used by Objective-C to divine which method will be executed in response to a particular message. We’ll get out our shovels and dig a lot more into the Objective-C method dispatch mechanism in the next chapter.



0x02 两个重要的泛型编程术语


接口(Interface)

接口是类为对象提供的特性描述。

Theinterface is the description of the features provided by a class of objects. For example, the interface for class Circle declares that circles can accept the draw message.


实现(Implementation)

实现是使接口能正常工作的代码。

The implementation is the code that makes the interface work. In our examples, the implementation for the circle object holds the code for drawing a circle on the screen. When you send the draw message to a circle object, you don’t know or care how the function works, just that it draws a circle on the screen.

你可能感兴趣的:(Objective-C,Objective-C基础教程)