学习Obj-C时候看书看到的一个能帮助很好地理解OOP中Class,Object和 Methods 概念的段落。
Consider an example from everyday life. Let’s assume that you own a car, which is obviously an object, and one that you own. You don’t have just any car; you have a particular car that was manufactured in a factory, maybe in Detroit, maybe in Japan, or maybe someplace else. Your car has a vehicle identification number (VIN) that uniquely identifies that car here in the United States.
In object-oriented parlance, your particular car is an instance of a car. Continuing with the terminology, car is the name of the class from which this instance was created. So each time a new car is manufactured, a new instance from the class of cars is created, and each instance of the car is referred to as an object.
Your car might be silver, have a black interior, be a convertible or hardtop, and so on. In addi- tion, you perform certain actions with your car. For example, you drive your car, fill it with gas, (hopefully) wash it, take it in for service, and so on.
—-Stephen G. Kochan, Programming in Objective-C - 6th Edition
例子:汽车
车有好多种,丰田、大众、宝马、奔驰…
car就是一个class,丰田宝马等不同牌子的车就是car类的实例 instance。每个实例就是一个object。
本文通过汽车的例子,深入浅出地介绍了面向对象编程(OOP)中的类(Class)、对象(Object)及方法(Methods)的概念。以具体汽车为实例,阐述了如何创建类的实例,以及对象的特性和行为。
959

被折叠的 条评论
为什么被折叠?



