This document was written by CS 290W TA Joshua Kay and was last modified
You have now been introduced to Objects, and also properties and methods of Objects.You know that Classes are generic definitions of Objects, used when you want to create a specific Object.
Now let's talk about Events, briefly.
Events are just what they sound like - happenings around the object which can stimulate the object in some way.
Most objects have built-in methods which can handle Events - In Java 1.1 these methods are called Listeners.
Due to limitations of Netscape 4.05, we will be learning Java 1.02 - which has slightly different Event Handling.
We will go into this in great detail later, so hold on for now.
We'll leave you with an example - you create a Button named myButton. Button is a predefined class of the java.awt package.
So we have to create an Event Handling method to control what happens when the user clicks on the myButton with his mouse.
-----------
We now know what Objects are, how they are defined, how they respond to Events, and what methods they have.
So what's the big deal about OOP?
Let's take a closer look at Objects. What are they, exactly?
Objects are nothing but specific instances of classes, with unique properties and methods.
We can look at an object as a set of properties, with methods which can manipulate those properties.
Objects are somewhat alone, in that they support themselves. An
example would be a die object:
-a die object can roll itself, to get its value
- in the real world we have to roll the die, but in programming we try to make things self-contained.
You can replace one object with another, without making huge changes in the program, but this might have consequences
-Example - You build a house out of Legos - you take off
one of the beams and replace it with a small one
The house might fall, or there could be a draft and Lego
rats can get inside.
More examples --
The Physics Building is a Building Object. The room we are in would be considered a Classroom object, full of People objects.
Students and Teachers would be considered two forms of People objects.
We are all wearing clothes - represented by Clothes objects.
This is broken down to Blue Jeans objects, T-shirt Objects, etc.
And remember all of the other objects in the room - Desks, Tables, Chairs, Doors.
So we need to look at one last thing, to really grasp OOP.
We have Objects, created from Classes, we know how they interact - but how are they related?
The relation between objects is known as inheritance.
For instance - we have Ball class - we'll call this the superclass.
Now we need a Basketball class - well, this inherits from the Ball class.
This is because Basketball, Football, Soccerball, Golf ball - they are all types of ball - hence they inherit certain things.
Let's look at this in a Family sort of way.
Josh Kay is his father's son. Josh has certain properties - Height, Eyecolor, Haircolor, etc. - that he inherited from his dad.
So, Josh is a subclass of the Kay object.
However, Josh has certain characteristics of his own as well. - He is not an exact copy.
Let's look at bodies of water. We have salt-water versus freshwater, first, right?
Now - we look at saltwater - we have oceans and seas, and the salt lake in Utah.
So, the Pacific Ocean is a subclass of oceans which is a subclass of saltwater which is a subclass of bodies of water.
Lake Michigan is one of the Great Lakes.
It might be considered a subclass of Lake which is a subclass of freshwater which is a subclass of bodies of water.
Java does NOT support multiple inheritance
-Ex: Salt Lake in Utah is a Lake, but it's also saltwater
- It would have to inherit from both Saltwater and Freshwater, because Lake is a subclass of Freshwater
- Java does not allow this - so you would have to program around it
- This does cause some limitations - however - it makes most programming in Java much easier