In the "real" world, objects are the entities of which the world is comprised. Everything that happens in the world is related to the interactions between the objects in the world. Just as atoms, which are objects, combine to form molecules and larger objects, the interacting entities in the world can be thought of as interactions between and among both singular ("atomic") as well as compound ("composed") objects. The real world consists of many, many objects interacting in many ways. While each object may not be overly complex, their myriad of interactions creates the overall complexity of the natural world. It is this complexity that we wish to capture in our software systems.
In an object-oriented software system, objects are entities used to represent or model a particular piece of the system.
Objects are the primary units used to create abstract models.
There are a number of schools of object-oriented programming, which differ slightly on how they view objects. Here, we will take a "behaviorist" (our term) stance:
An object is characterized solely by it behaviors.
Essentially this defines an object by the way it interacts with its world. An object that does not interact with anything else effectively does not exist. Access to internally stored data is necessarily through some sort of defined behavior of the object. It is impossible for an outside entity to truly "know" whether or not a particular piece of data is being stored inside of another object.
This does not mean however, that an object may not contain data (information) in fields. The essence of the object is in how the object behaves in relationship to or as a result of its data, should it contain any.
The existence of data in an object is an implementation technique used to generate the required behavior of that object.
- 瀏覽次數:1275