You are on page 1of 1

School of Computer Science &

Classes and OO Programming


Information Technology
 An OO program consists of at least one (usually
many more) inter-dependent classes.
 A class is a user-defined data type that describes
G6DICP - Lecture 11 the properties and capabilities of the real-world
objects with which the program has to deal.
 A class is a generic type of “thing”, whereas a
Classes & Objects specific “thing” (an instance of the class) is an
Object.
 A class definition consists of both the properties
(ie data) and the capabilities (ie program code)
of that class.
2

An Analogy Using Classes


 Consider the class Pen  Instances of class Pen
ie pens in general, not any ie specific pens, belonging
 Definition
one pen in particular. to specific people.  Declaration of variables

 Tim’s boardwriter  Instance variables - specific to one instance of a class


 Properties (variables)
 Class variables - shared by all instances of that class
 Colour  Tim’s biro
 Definition of methods
 Thickness  Alan’s pen
 A method is the program code required to perform a specific task with the
 Capabilities (methods)  Instances of the class class.
 Remove lid Pen are called Objects.  Methods consist of statements.
 Draw line  Instantiation
 Draw circle  Usually an instance of a class needs to be created before it can be used.
 Replace lid  Some classes (especially utility classes) have methods and variables that
can be used without instantiation.

3 4

The Purpose of OO
Programming
 Classes should model the real world - thus
leading to efficient coding.
 Classes are reusable.
 Libraries of reusable classes (“class libraries”)
make sophisticated functionality easily available.
 This is a “construction kit” approach to
programming.
 For example - consider graphical programs:
 Window class
 Text box
 Button class
5

You might also like