Classes and objects
A class is a way of describing a category of objects
that can be viewed as similar in some way. For example, a public library might have on its
shelves the following objects:
- a copy of the novel ‘War and Piece’
- a copy of the text book ‘Java How to Program’
- a copy of the CD album ‘Yellow Submarine’ by the Beatles
We can describe all these objects as
instances of the class LibraryItem. They have many
things in common. All these objects have similar attributes, such as:
title, author(s) or composer(s), loan status, loan duration, due
date, loan fee (books might be free, but CDs might be loaned at a charge of 50p per week),
late return charge
These objects also have similar operations, such as:
- set loan status to ‘on loan’ or ‘on shelves’
- tell us the ‘loan fee’ value
- set the ‘due date’ to be the first working day after the
current date plus the ‘loan duration’
Warning: we are using the value of certain
attributes such as a book title to distinguish between book instances because we are human
and can distinguish using content. But we can also identify two books of identical title
and content, like two copies of the famous object technology book Design Patterns.
Always remember that software objects have individual identity.
Of course, modelling is a personal activity, and
different people (or teams) may come up with different classes, attributes and operations.
There are differences between each of the three
LibraryItem objects listed above. However, they are more similar to one another than they
are to, say, a hat-stand or a cheese sandwich or a bank account! Furthermore, it makes
sense for them to be modelled as objects that are instances of the same class.
Note that, by convention, the names of classes are
written with an initial capital letter (e.g. Library, not library)
and this convention is followed in this module.
In fact, when writing in the Java programming
language, spaces are not permitted in the names of classes, so in a Java program we might
use the class name LibraryItem.
Such coding conventions are considered in the
module units that follow.
Object-oriented analysis and design the
process of breaking down a system (for example the stock department of a DIY shop) into
the classes it contains, and finding how these classes are related. It also involves
modelling how do decide when objects of each class will need to be created and destroyed
by computer programs.
Object-oriented programming is the process of
writing sections of program that correspond to each class.
Back
to top

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg
|