Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Always remember that Object-Orientation and computing was intended to make thinking about programming closer to thinking about the real world. And that means if we ask what is an object in a computer program, we first ask what is an object in the real world? Well, we instinctively know what that means, but it's tough to describe without saying something vague like an object is a thing. So is this apple an object in real life? Sure. This desk? Well, of course. This mug? Absolutely! They are all objects, these are all things.
We understand that objects are separate from one another. They have their own existence, their own identity that is independent of other objects. This is a mug, and this is a mug, but they are not the same mug, they are not the same object. They are different objects, they have their own identity. We know that being an object has nothing to do with complexity. An apple is an object, but so is an aircraft carrier, so as an iPhone, and we know that one object might contain other objects.
But we still understand their separateness, this does not confuse us. We know that objects have characteristics, inherent properties that describe them. A mug can be full or empty. An apple can be green or red, a lamp can be off or on. These are the attributes of any object, things like color, weight, and size. They describe the current state of an object and the state of one object is independent of another. We turn one lamp off, it does not turn all the lamps in the world off.
And most objects have multiple attributes. A mug can be full or empty or somewhere in between but at the same time it could be black or white or some other color. It could be large or small and in the real world objects have behavior, a telephone can ring, an airplane can fly, and that behavior is specific to the type of object. An apple does not ring, a telephone does not fly. But those three things, identity, attributes, and behavior are the same three things that describe an object in an object-oriented programming language.
Objects in a computer program are self-contained. So they have identity separate from other objects. They also have their own attributes. Information that describes their current state, and they have their own behavior, things they can do. Now while in the real world we tend to only use the word object for things we can see and touch, but in computing we can take it further. Sure, in a computer program, we often have objects that represent real world items like car, house, apple, but also a date could be an object, a time, a bank account could be an object, and you can't touch and hold a bank account in real life.
But it is still a well-defined idea, and even in real life it meets our definition of object. It has identity. One bank account is separate from another bank account. It has attributes or data that describe its current state. An account number, a balance, an account holder name, and it has behavior. You can deposit to a bank account, you can withdraw from it, you can open it or close it. And just as they don't have to be physical items, objects in a computer program are not just the things with a visual appearance on the computer screen.
Sure, buttons and images and spaceships can all be objects, but so could invisible things like a timer or an array. So we don't just focus purely on a physical items or visible items when you are working with objects in a computer program. Now when you're new to Object-Oriented Design, it can be a bit of a challenge to figure out if something in your application is a new potential object. It's easy when your application needs something like car, employee, document, but say you're building an event management application.
Well, what about something like event? Would an event be an object? Well, first, one clue is is the word a noun? Nouns aren't just physical things, but people, places, and ideas or concepts. But if you don't want to do that, here's even a simpler suggestion. If you were talking about any conversation, could you put the word "the" in front of it? The mug, the apple, the car, the television, sure, but also the bank account, the time, the date, the event. Those work too.
Those could be objects. But you wouldn't say the saving, the printing, the exploding. Those would be verbs. They would be behaviors of objects, not objects themselves. But where do these objects come from? They don't magically appear in our program, so how do we make them? Well, to do that, there is another word we must explore that goes hand in hand with object, and that word is class.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101488 Viewers
61 Video lessons · 88253 Viewers
71 Video lessons · 72124 Viewers
56 Video lessons · 103888 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.