I am trying to understand the concept of classes and objects, and I came across to the words "type" and "instance". Does type mean exactly the same thing as class, and instance for object? Or is there a difference in between, such as a usage difference etc.?

有帮助吗?

解决方案

Quick Example

A class is the design specs for a MacbookPro, an instance is your MacbookPro specifically.

A type is just a class that defines your class, so that we can look at a blueprint and ask if design spec is MacbookProBlueprint. This is useful when we want meta-data about our classes (or other types). Think of a type as an Amazon.com entry, that would have lots of information about the MacbookPro such as processor speed and capabilities but not enough to actually build the object.

An object is your MacbookPro, or my car, or anything. Everything is an object which has implications larger than the scope of this question, but is fundamental nonetheless.

其他提示

The SuperCollider book does a nice job of both summarizing programming concepts (particularly object oriented ones) and simultaneously demonstrating them in the SuperCollider language. See here for more information. It is a great resource, and the website has all of the code in a downloadable archive.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top