CSC 202 Session 1
CSC 202 Session 1
1|Page
Despite the introduction of functions, large programs in procedural programming
languages are still excessively complex.
In a large program, there could be many functions and many global data items.
This results to a large number of potential connections between functions and
global data as illustrated in Figure 2.
2|Page
Figure 2: Connections between Functions and Data
This large number of connections create problems in several ways:
i. Firstly, it makes a program’s structure difficult to conceptualize. Fewer connections
make it easier to capture data and functions that will be needed in a program.
ii. Secondly, it makes the program difficult to modify. A change made in a global data
may necessitate rewriting all the functions that access that data. When data items
are modified in a large program it may not be easy to identify the exact functions
that is accessing the data, and even when you figure this out, modifications to the
functions may cause them to work incorrectly with other global data items.
Everything is related to everything else, so a modification anywhere has far-
reaching, and often unintended consequences.
3|Page
3. The Object-Oriented Approach
Object oriented languages attempt to combine both data and the functions that operate
on that data into a single unit called an object. An object could be any entity of interest
being studied. This entity will have an attribute (which are its unique characteristics) and
behaviours (which defines operations that can be performed on the object) e.g. an object
could be a STUDENT, its attributes could be: name, matric_no, age, level, dept etc while
its behaviours could be course_registration, room_application, school_fees_payment,
medical_clearrance etc.
The data of an object in OOP cannot be accessed directly i.e. they are hidden, so they are
safe from accidental alteration. They can only be accessed by calling its member functions.
This feature is called data/information hiding
4|Page
4. Characteristics/ Features of Object-Oriented Languages
i. Objects: these are any entity of interest in any scenario being considered. This
could be physical objects, Human entities (Employees, Students, Customers),
Collections of data (An inventory, A personnel file) etc.
ii. Classes: these are collection of similar objects, therefore, an object is called an
instance of a class. E.g. The vehicle class could have cars, trucks, buses, motorcycles
as objects. A University_personnel class could have students, lecturers,
admin_officers, Typist, drivers, security_man as objects.
A class can be divided into sub-classes, where the original class is called the base class
and the sub-classes that share the characteristics of the base class, but add their own
as well are called the derived classes.
5|Page
Figure 4: Relationship between a Base Class and Derived Classes
iii. Inheritance: the ability of a derived class to inherit some characteristics from their
base class in addition to their own unique characteristics. Since I know that a
derived class can automatically share and inherit the features of a base class, I don’t
need to declare these features for the derived class again.
iv. Code Reusability: another important feature of OOP is code reusability. In this
instance, a class that has been written, created, and debugged can be distributed to
other programmers for use in their own programs. This is similar to the way a library
of functions in a procedural language can be incorporated into different programs.
6|Page
A programmer can take an existing class and, without modifying it, add additional
features and capabilities to it. This is done by deriving a new class from the existing
one. The new class will inherit the capabilities of the old one, but is free to add new
features of its own.
Example
You might have written (or purchased from someone else) a class that creates a
menu system, such as that used in Windows or other Graphic User Interfaces (GUIs).
This class works fine, and you don’t want to change it, but you want to add the
capability to make some menu entries flash on and off. To do this, you simply create
a new class that inherits all the capabilities of the existing one but adds flashing
menu entries.
7|Page
UML Diagrams
Class diagrams show the relationships among classes, object diagrams show how specific
objects relate
Sequence diagrams show the communication among objects over time.
Use case diagrams show how a program’s users interact with the program, and so on.
Study Questions
i. Enumerate the advantages of OOP over Procedural programming languages.
ii. Why is it difficult to manage large programs in procedural programming language?
iii. Establish the relationship between class and objects using real life scenario excluding
those used in the textbook.
iv. Explain the relationship among classes, sub-classes and inheritance.
v. How is code reusability related to inheritance?
vi. Explain the concept behind Polymorphism.
References
Robert Lafore (2002), “Object-Oriented Programming in C++”, Sams Publishing Fourth
Edition
8|Page