Introduction to Object-Oriented programming.
What is an object in the "real-world"?
- Something perceptible by the vision or touch.
- Something intelligible or perceptible by the mind (philosophically
speaking)
- A focus of attention, feeling, thought or action
(Definitions found on the dictionary.)
Imagine now a written document as an object. Think of the characteristics of
this object.
- length: number of pages.
- title: what the written document is all about.
- author: the person that wrote the document
- material: paper
The material and the author are objects themselves. Length and title are
characteristics of the written document. We can do the as we did for the book
with the author and the material....
Author as an object
- name
- social security number
- address
- phone number
If we keep on going.... we could go on forever. There is a point where
we want to stop. Objects are made of other objects...
We want a car.
We can buy it at the dealer :-)
We can build it ourselves.
- we need the parts
- we need to put it together
Do we buy the engine or do we build one?
Lets think JAVA!
How do we model objects in JAVA?
Imagine now the same written document as a JAVA object. Think of the
characteristics of this object.
- length: number of pages.
- title: what the written document is all about.
- author: the person that wrote the document
- material: paper
- length can be an integer number
- title can be a string
- author can be a
- string containing the name
- string containing an ID number
- an independent object containing all of the above and maybe more...
Think ....
- If you want to build a car...will you buy the engine or to build it?
- If you are writing a tem-paper, do you manufacture the paper?
JAVA has predefined classes and objects for us to use. We don't have to build
everything from scratch.