0% found this document useful (0 votes)
115 views11 pages

Handout OOP

This document provides an introduction to object-oriented programming concepts including objects, classes, methods, and the four pillars of OOP: encapsulation, abstraction, polymorphism, and inheritance. It defines key terms like object, class, method, and describes the components of a class and method in Java. The document includes examples of objects like a Dog and Car class to illustrate objects and their properties. It also includes a figure showing the four pillars of OOP. Finally, it begins discussing abstraction as the first pillar.

Uploaded by

James Yape
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views11 pages

Handout OOP

This document provides an introduction to object-oriented programming concepts including objects, classes, methods, and the four pillars of OOP: encapsulation, abstraction, polymorphism, and inheritance. It defines key terms like object, class, method, and describes the components of a class and method in Java. The document includes examples of objects like a Dog and Car class to illustrate objects and their properties. It also includes a figure showing the four pillars of OOP. Finally, it begins discussing abstraction as the first pillar.

Uploaded by

James Yape
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Name :

Course, Year &


Section :
Date of Submission : August 24, 2020
Address :
Contact Number and
Email Add :
Disclaimer: This material is used for instructional purposes only and is not intended for sale. Should it be
distributed to persons other than those enrolled in this subject or should it be dispensed for commercial
purposes, the ESSU and the faculty who compiled this material will not be responsible for any claims of the
original authors.

1
Break the chain of COVID19 Infection
 Wear face mask
 Frequent hand washing
 Proper hygiene
 Use alcohol and sanitizer
 Always observe physical distancing
 Cover your mouth when coughing and sneezing

These instructional activities will be good for __1 week______.

Preliminaries

University Vision
A synergistic multi-campus university producing competent, value laden and globally
competitive graduates who are proactive in promoting the socio-economic prosperity of the
country.

University Mission
The University shall primarily provide advanced education, higher technological
professional instruction and training in the fields of agriculture, arts and sciences, business
and industry, computer and information technology, education, engineering, environmental
sciences, fisheries, forestry, law and criminal justice, medicine and allied sciences and other
related fields of study. It shall intensify its research, extension and production functions and
provide progressive leadership in its areas of specialization.

Core Values
Excellence
Integrity
Accountability

Quality Policy
We commit to provide quality instruction, research, extension and production grounded
on excellence, integrity and accountability as we move towards exceeding stakeholders’
satisfaction in compliance with relevant requirements and well-defined continual improvement
measures
“Dekalidad na edukason, Kinabuhi na mainuswagon”

Subject Teacher’s Contact Details

Name : __JARED HAREM Q. CELIS_____


Contact No. : __0905-299-2721_______________
Email Address :[email protected]_

2
Preliminary Activity:
A. Vision and Mission
 What personal and professional qualities should you possess to become
globally competitive graduate?
 How will the University prepare you to become professional in your chosen
field of specialization?
B. Course Content, Requirements and Marking System (Please read the course
guide)

Unit 1: OBJECT ORIENTED CONCEPTS

Introduction
Object-Oriented Programming (OOP) refers to a type of programming in which
programmers define the data type of a data structure and the type of operations that can be
applied to the data structure. The primary purpose of object-oriented programming is to
increase the flexibility and maintainability of programs. Object oriented programming brings
together data and its behavior (methods) in a single location (object) makes it easier to
understand how a program works.
In this chapter, we will introduce the basic core concepts of object-oriented
programming, its distinction to procedural oriented programming, abstract data types and of
course to better understand the foundations of OOP and its application in creating powerful,
scalable, and dynamic programs.

Learning Outcomes:
At the end of this lesson, you are expected to:
1. Define Object-Oriented Programming.
2. Identify the different core concepts of OOP.
3. Distinguish the difference of procedural oriented programming and object-oriented
programming.
4. Discuss the basic principles OOP using Java programming language.
5. Discuss the abstract data types in Java.

ACTIVITY
At this point, I want you to remember your prevus computer programming 1 and 2
courses/lessons about computing. After this, please accomplish the K-W-L chart. First, answer
the (K) what you know and (W) what you want to know about the lesson. Once you finish
lesson 1, go back to the K-W-L chart again and answer (L) what you learned and need to be
discovered. You may use the template below, or you can re-encode the table.

3
K-W-L Chart
K- what I know W- what I want to know L- what I learned and still
need to learn

LESSON PROPER

Lesson 1: Core Concepts of Object-Oriented Programming


The object-oriented programming model revolves around the concept of
Objects that contain data and methods. We will cover each and every feature
of OOPs in detail so that you won’t face any difficulty understanding OOPs
Concepts.

What is an Object?
Object is a bundle of data and its behavior (often known as methods). It is an instance of
a Class. It contains properties and can be a combination of variables, functions, and data
structure. This is usually a noun.
An object in object-oriented programming consists of:
1. State: It is represented by attributes of an object. It also reflects the
properties of an object.
2. Behavior: It is represented by methods of an object. It also reflects the
response of an object with other objects.
3. Identity: It gives a unique name to an object and enables one object to
interact with other objects.
Examples:
Object: Dog Object: Car
Identity: Dog Identity: Car
State/Attributes: Breed, Age, Color State/Attributes: Color, Model, Brand
Behavior: Bark, Wag Tail, Eat Behavior: Accelerate, Brake, Slow down

What is a Class?
A class is a user defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one type. In
general, class declarations can include these components, in order:
1. Modifiers: A class can be public or has default access.
2. Class name: The name should begin with an initial letter (capitalized by
convention).
3. Superclass (if any): The name of the class’s parent (superclass), if any,
preceded by the keyword extends. A class can only extend (subclass) one
parent.
4. Interfaces (if any): A comma-separated list of interfaces implemented by the
class, if any, preceded by the keyword implements. A class can implement more
than one interface.

4
5. Body: The class body surrounded by braces, { }.

Example:

What is a Method?
A method is a collection of statements that perform some specific task and return result to
the caller. A method can perform some specific task without returning anything. Methods allow
us to reuse the code without retyping the code. In Java, every method must be part of some
class. Methods are time savers and help us to reuse the code without retyping the code. This
is usually a verb.
In general, method declarations has six components:
1. Access Modifiers: Defines access type of the method i.e. from where it can be
accessed in your application. In Java, there 4 type of the access specifiers.
a. Public: accessible in all class in your application.
b. Protected: accessible within the package in which it is defined and in
its subclass(es) (including subclasses declared outside the package).
c. Private: accessible only within the class in which it is defined.
d. Default (declared/defined without using any modifier): accessible within
same class and package within which its class is defined.
2. The return type: The data type of the value returned by the method or void if does not
return a value.
3. Method Name: the rules for field names apply to method names as well, but the
convention is a little different.
4. Parameter list: Comma separated list of the input parameters are defined, preceded
with their data type, within the enclosed parenthesis. If there are no parameters, you
must use empty parentheses ().
5. Exception list: The exceptions you expect by the method can throw, you can specify
these exception(s).
6. Method body: it is enclosed between braces. The code you need to be executed to
perform your intended operations.

Example:

5
There are Four (4) Principles that makes a language object-oriented. These are
Encapsulation, Data Abstraction, Polymorphism and Inheritance. These are also called as four
pillars of Object Oriented Programming.

Figure 1. Four pillars of Object-Oriented Programming


1. Abstraction
Abstraction is a process where you show only “relevant” data and “hide” unnecessary
details of an object from the user. The property by virtue of which only the essential details are
displayed to the user. The trivial or the non-essentials units are not displayed to the user. In
this OOP concept, all object have their separate lifecycle, and there is no owner.
Example:
o Many students can associate with one teacher while one student can also
associate with multiple teachers.
o A method that adds two integers. The internal processing of the method is hidden
from the outer world.

2. Inheritance
In OOP, computer programs are designed in such a way where everything is an object
that interact with one another. Inheritance is one such concept where the properties of one
class can be inherited by the other. It helps to reuse the code and establish a relationship
between different classes. It is the mechanism in java by which one class is allow to inherit
the features (fields and methods) of another class.

6
As we can see in the image, a child
inherits the properties from his father.
Similarly, in Java, there are two
classes:
1. Parent class (Super or Base class)
2. Child class (Subclass or Derived
class)
A class which inherits the properties is
known as Child Class whereas a class
whose properties are inherited is
known as Parent class.

Important Terminology in Inheritance:


 Super Class: The class whose features are inherited is known as superclass (or a
base class or a parent class).
 Sub Class: The class that inherits the other class is known as subclass (or a derived
class, extended class, or child class). The subclass can add its own fields and methods
in addition to the superclass fields and methods.
 Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to
create a new class and there is already a class that includes some of the code that we
want, we can derive our new class from the existing class. By doing this, we are reusing
the fields and methods of the existing class.

3. Encapsulation
Encapsulation simply means binding object state (fields) and behavior (methods)
together. It is the mechanism that binds together code and the data it manipulates.

Figure 2. Diagram of encapsulation.


Example:

7
Let us try to understand the above code. I have created a class Employee which has
a private variable name. We have then created a getter and setter methods through which we
can get and set the name of an employee. Through these methods, any class which wishes
to access the name variable has to do it using these getter and setter methods.

4. Polymorphism
Polymorphism means taking many forms, where ‘poly’ means many and ‘morph’ means
forms. It is the ability of a variable, function or object to take on multiple forms. In other words,
polymorphism allows you define one interface or method and have multiple implementations.
Example:

Figure 8. Example diagram of Polymorphism.

Let’s consider this real world scenario in cricket, we know that there are different
types of bowlers i.e. Fast bowlers, Medium pace bowlers and Spinners. As you can see
in the above figure, there is a parent class - BowlerClass and it has three child
classes: FastPacer, MediumPacer and Spinner.

Bowler class has bowlingMethod() where all the child classes are inheriting this method.
As we all know that a fast bowler will going to bowl differently as compared to medium pacer
and spinner in terms of bowling speed, long run up and way of bowling, etc. Similarly a medium
pacer’s implementation of bowlingMethod() is also going to be different as compared to other
bowlers. And same happens with spinner class. The point of above discussion is simply that
a same name tends to multiple forms. All the three classes above inherited
the bowlingMethod() but their implementation is totally different from one another.

Lesson 2: Procedural Oriented Programming vs Object-Oriented


Programming

Procedural Oriented Programming can be defined as a programming


model which is derived from structured programming, based upon the concept of calling
procedure. Procedures, also known as routines, subroutines or functions, simply consist of a
series of computational steps to be carried out. During a program’s execution, any given
procedure might be called at any point, including by other procedures or itself. The issue that
is obvious in Procedural Programming is that if an edit is needed to the program, the developer
must edit every line of code that corresponds to the original change in the code.

8
Languages used in Procedural Programming:
FORTRAN, COBOL, ALGOL, BASIC, Pascal, and C.
Example:

Figure 3. Calls in Procedural Programming


In the above figure shown, functions operates on either local or global data.
Object-Oriented Programming can be defined as a programming model which is
based upon the concept of objects. Objects contain data in the form of attributes and code in
the form of methods. In object oriented programming, computer programs are designed using
the concept of objects that interact with real world. Object oriented programming languages
are various but the most popular ones are class-based, meaning that objects are instances of
classes, which also determine their types.

Languages used in Procedural Oriented Programming:


Java, C++, C#, Python, Ruby, Pearl, Swift, Scala, Php, JavaScript.
Example:

Figure 4. Message passing between objects


In OOP, objects exists and objects interact with other objects (message passing).

9
Difference between Object-Oriented Programming and Procedural Programming
Procedural Oriented Programming Object-Oriented Programming
In procedural programming, program is In object oriented programming,
divided into small parts program is divided into small parts
called functions. called objects.
Procedural programming follows top Object oriented programming
down approach. follows bottom up approach.
There is no access specifier in Object oriented programming have
procedural programming. access specifiers like private, public,
protected and etc.
Adding new data and function is not Adding new data and function is easy.
easy.
Procedural programming does not have Object oriented programming provides
any proper way for hiding data so it data hiding so it is more secure.
is less secure.
In procedural programming, overloading Overloading is possible in object
is not possible. oriented programming.
In procedural programming, function is In object oriented programming, data is
more important than data. more important than function.
Procedural programming is based Object oriented programming is based
on unreal world. on real world.

ASSESSMENT
Direction: Do not write anything in this learning material. Please provide a separate paper for
your answers and indicate your name, course & year, and section.
1. What are the four basic principles of OOP? Provide a brief description of each and give
atleast one example.
2. In your own understanding, state the distinction between Procedural-Oriented
Programming and Object-Oriented Programming.
3. In a real world setting, cite an example of an object and a class. Discuss briefly your
examples.
4. Determine the names of the highlighted terms in the source code.

4.1 4.2 4.3

Public int MaxValue()


{
int x;
int y;
4.4
if (x > y)
return x;
else
return y;
}
10
5. What is method? Write a simple java code creating a method with the following
components:
a. Access Modifiers
b. The return type
c. Method name
d. Parameter list
e. Exception list
f. Method body

REFERENCES:
[1] Herbert, Schildt. (2019). Java A Beginner’s Guide Eight Edition, McGraw-Hill
Education, New York, USA.
[2] Eck, David J. (2006). Introduction to Programming using Java, Creative Commons,
California, USA.
[3] Gosling, J., Joy, B., Steele, G., Bracha, G., & Buckley, A. (2015). The Java Language
Specification, Java SE 8th Edition, Oracle America, Inc., California, USA.

Suggested Readings:
[1] https://www.edureka.co/blog/object-oriented-programming/
[2] https://www.javatpoint.com/java-tutorial
[3] https://www.tutorialspoint.com/java/index.htm

Reminder:

Submit this learning material securely packaged (please provide an extra plastic envelope
intended for the second set of learning materials) to the campus security personnel or as advised
by your subject teacher, on the prescribed date and time.

11

You might also like