Object-oriented programming has a few basic principles: abstraction, inheritance, encapsulation, and polymorphism.
- Abstraction — extracting functionality from logic
- Inheritance — deriving functionality from an abstraction
- Encapsulation — separating functionality between abstractions
- Polymorphism — abstracting in multiple forms
These principles are all combined to create objects. But what really are objects? The four principles above are used to create useful objects; but what is an object itself?
Defining an object
Let's take the common example of a
Person. What are some characteristics of a person?
- Hair color
We would lump these attributes into the person's state. A person's age, hair color, and height are mutable properties that depend on time, condition, and countless other variables. Essentially, an object's state is any mutable attribute.
Now, what can a person do? Well, a person could
These are actions. It is important to differ between state and action; one could say a person "is running", but grammatically, "running" is a noun describing the person. We can now form the distinction that state is nouns and adjectives, and actions are verbs. As a definition, actions are procedures carried out by an object.
Occasionally, object-oriented programming guides list events as a separate property of objects. However, in accordance with the definition of action, events are the actions of response.
What else is there? Well, a person has to be born at some point. The creation of an object is its construction. And at some point, that person will die; an object has a possible deconstruction.
Construction and creation
A key distinction must be made between the meaning of construction and creation. Construction is the assembling of an entity from previous entities; creation is the spontaneous existence of an entity from no previous entities (but not necessarily acausal).
I'd be willing to make the conjecture that every object is constructed in one form or another. Ideas are constructed from previous ideas, and abstractions are constructed from previous abstractions.
The same thing with deconstruction: by the first law of thermodynamics, nothing material is truly "destroyed." The issue is making this claim with the ideal: are ideas ever "destroyed?" It's a difficult argument to make.
Metaphysics and objects
These properties of objects sets the stage for tying OOP together with metaphysics: state, action, construction, and destruction.
Every entity in the real contains these same properties.
Everything has state, action, has been constructed, and will eventually be deconstructed. Essentially, as is the purpose of OOP, every object reflects a real entity.
What surprised me was how accurately a model of programming reflects our own existence.