Week 1 Sessions 1-2 Introduction To OOP
Week 1 Sessions 1-2 Introduction To OOP
Week 1 Sessions 1-2 Introduction To OOP
Specific Objectives:
At the end of the topic session, the students are expected to:
Cognitive:
Affective:
Psychomotor:
MATERIALS/EQUIPMENT:
o topic slides
o OHP
TOPIC PREPARATION:
TOPIC PRESENTATION:
This will be the suggested flow of discussion for the course topic:
concept are.
Procedural programming
Object-oriented programming
OOP has become the most widely used paradigm. Instead of focusing
on what the system has to do, OOP focuses on what objects the system
contains and how they interact towards solving the programming
problem.
To illustrate further what an OOP is, we will cite an example (refer to the
slide). A car is an object that uses speed and direction to transport
people to a different location. This car object encapsulates all the
functions that it needs to get its job done. It has a switch to turn it on, a
wheel to control its direction, and brakes to slow it down. These
functions directly manipulate the car’s data, including direction, position,
and speed.
Illustration of OOP
When you travel in a car, however, you don’t have to know the details of
how these operations work. To stop a car, for example, you simply step
on the brake pedal. You don’t have to know how the pedal stops the car.
You simply know that it works.
All these functions and data work together to define the object called a
car. Furthermore, all these functions work very similarly from one car to
the next. You’re not likely to confuse a car with a dishwasher, tree, or
playground. A car is a complete unit — an object with unique properties.
Objects
Classes
Abstraction
Inheritance
Encapsulation
Polymorphism
Introduction to OOP
Page 3 of 8
Object-Oriented Programming
The class implementation specifies the data structure for each of its
objects. For example, an Employee class might include data about
exemptions, position, salary, phone extension, and so on. In addition,
each class defines a set of permissible operations that allow access to
and modification of object data. An Employee class might include
operations such as hire, promote, and change phone extension for an
Employee class. Details of the class include the specification that
describes an operation.
Introduction to OOP
Page 4 of 8
Object-Oriented Programming
Abstraction Abstraction
Page 7 of 15
In OOP, abstraction is one of three central principles along with
encapsulation and inheritance. Abstraction is a programming feature
that allows a programmer to hide all but the relevant information (to the
problem at hand) about an object in order to reduce complexity and
increase efficiency. A programmer would use abstraction, for example,
to note that two functions perform almost the same task and can be
combined into a single function. For example, your Honda car may be
treated as a common car most of the time (e.g., when driving the car), as
a Honda car when attributes specific to Honda cars are required (e.g.,
when replacing specific components/parts), or as your specific Honda
car (e.g., when selling the car).
Encapsulation Encapsulation
Pages 8-9 of 15
Encapsulation refers to the hiding of data (attributes) and methods within
an object. It protects an object’s data from corruption. If all programs
could access the data in any way users wished, the data could easily be
corrupted or misused. Encapsulation protects the object’s data from
arbitrary and unintended use.
Illustration of encapsulation
Introduction to OOP
Page 5 of 8
Object-Oriented Programming
Inheritance Inheritance
Pages 10-11 of 15
Inheritance is the process by which objects can acquire (inherit) the
properties of objects of another class. In OOP, inheritance provides
reusability. Additional features may be introduced into an existing class
without modifying it. This is achieved by deriving a new class, called a
subclass, from the existing one. The new class will then have the
combined features of both the classes.
For example, consider a Car class that defines everything common to all
cars. A Convertible subclass may then be defined from the Car class. A
Convertible then inherits properties from the Car class. That is, a
Convertible is a Car that has and can do everything a plain Car does.
This, however, has added mechanisms for and an added ability to lower
its top. Note that a Convertible is not an object. It is a class that inherits
from the Car class.
Illustration of inheritance
Introduction to OOP
Page 6 of 8
Object-Oriented Programming
Polymorphism Polymorphism
Pages 12-13 of 15
Polymorphism refers to the ability to process objects differently
depending on their data type or class. Specifically, it is the ability to
redefine methods for derived classes. For example, given a base class
Shape with a method to return the area of the shape. Polymorphism
enables the programmer to define different area methods for any
number of derived classes from Shape, such as circles, rectangles, and
triangles. No matter what shape an object is, applying the area method
to it will return the correct results.
Illustration of polymorphism
In the given figure (refer to the slide), both Student and Car have an
instance existing in class Application Form. Notice that both Student
class and Car class have the isRegistered() method. However, the way
a student registers is different from the way a car registers. For
instance, when a student number is required in the process when a
student registers. On the other hand, the registration of a car does not
need information such as a student number but rather say the chassis
and engine numbers.
For example, you can create an abstract class Shape which will be the
base class of different polygons. All members of the class Shape will be
inherited by the subclasses created from Shape. However, you cannot
create an object directly from the abstract class Shape.
Introduction to OOP
Page 7 of 8
Object-Oriented Programming
Interfaces Interfaces
Page 15 of 15
Interfaces allow you to create definitions for component interaction.
They provide another way of implementing polymorphism. Through
interfaces, you specify methods that a component must implement
without actually specifying how the method is implemented. You just
specify the methods in an interface and leave it to the class to implement
those methods.
EVALUATION/GENERALIZATION:
o Ask the students to write a brief essay outlining what they have
learned from the topic discussed.
o Ask the students to perform the laboratory exercise.
REFERENCES:
Introduction to OOP
Page 8 of 8