Abstract: What are objects?
What are objects?
Preface
This short tutorial covers the abstract definition of an object, as we know it in C++.
Before I give the final definition of an object, I'll cover aspects that play a role in the process of defining an object. Besides that, I'll present examples from the "real" world and translate them into knowledge related to the C++ programmer.
(Part 1 of 2) So what are objects: informal description
Entity. A word that can relate to a ghost, a car, a human being, a chair, a mortgage, a feeling, love. It is hard to think of a more abstract word than the word "entitiy". It can be absolutely everything.
But a programmer needs more than such a word. He or she needs something that is "tangible", something that is clearly defined and put in its place. The memory of a computer that is. Programmers call these things: objects. Objects are "real". They have a quantity,a clear shape, a behaviour and they are in a certain state. Just like humans. There is a quantity of humans, they have a distinctive shape, they have a certain behaviour, and are in a certain state (sleep, angry, happy, awake).
While the definition of an entity may depend upon the perception of a human being, an object is clearly shaped.
Objects are in a certain state.
Defining objects is the same thing as "looking for things". Usually a programmer does this by thinking and writing specifications (code) in a class.
Humans have a behaviour. A human can give you a cup of tea, or help you do the dishes. Humans can offer services. So can objects.
Objects can offer services.
Well, objects are unique, no two objects are the same. Take for instance twins. They might look the same in all aspects, but since they have their own personality, identity, they are by no means the same. Both of them are unique.This goes for objects too.
Objects are unique and have their own shape.
Lets wrap this informal part up. In general, one can say about objects:
1) Objects are clearly defined.
2) No two objects are the same.
3) Objects can offer services.
4) Objects are in a certain state.
(Part 2 of 2) So what are objects: its definition
An object is an instance of a class with the following essential properties:
1) Each object has its own identity.
2) Each object can have a behaviour.
3) Each object is in a state.
These essential properties are proposed by G. Booch (1991).
Lets elaborate these three essentials.
1) Identity
So how can you Identify objects? How do they have their own identity?
Each object persists in its own memory adress.
So we managed to define the word identity, implying at the same time their uniquenes.
2) Behaviour.
The behaviour of an object is the same thing as the kind of services an object delivers. A point-object can offer services to make a line. And a line-object can offer services to a CAD/CAM application. A server-object can offer services to a client-object. And (by our definition) a client-object can offer services to other objects. It all depends upon the context in wich the object is created.
3) State.
The state of an object is information about the object itself. For example, a point-object might actually hold a value, like (1,2). This is the state the point object is in right now.
Comment 1:
While I defined the uniqueness of an object by its adress in memory, one could easely connect the uniqueness of an object with its name. I've seen books and universities introduce this definition. For the sake of completeness I've added this comment.
Comment 2:
A class is NOT an object. A class is a definition. It is not "real". An object is. Though this might cause some problems. What about meta-classes? These are classes about classes. But this goes beyond the scope of this tutorial.
So there we have it. An abstract view on objects. I hope the student has now a firmer grip on thinking in terms of Object Oriented Programming
See you guyz next time,
Val
|