Sie sind auf Seite 1von 21

COMPETENCY-BASED LEARNING MATERIAL

Sector INFORMATION AND


COMMUNICATION TECHNOLOGY
(ICT)
Qualification Title PROGRAMMING NC IV

Unit of Competency Apply Object-Oriented


Program Language Skills
Module Title Applying Object-Oriented Program
Language Skills

STI Education Services and Group Inc.


Malaybalay Campus
2nd floor MS Building, Fortich Street, Malaybalay City
PROGRAMMING NC IV

No. Unit of Competency Module Title Code


1. Design program logic Designing program logic ICT313328
Apply program Applying program
2. ICT313329
development approach development approach
Apply object-oriented Applying object-
3. program language oriented program ICT313330
skills language skills
Apply programming Applying programming
4. skills in a second skills in a second ICT313331
language language

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 2 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
HOW TO USE THIS COMPETENCY-BASED LEARNING MATERIAL

The unit of competency, Apply object-oriented program language


skills, is one of the competencies of PROGRAMMING NC IV, a course
which comprises the knowledge, skills and attitudes required for a
trainee to possess.
You may be required to go through a series of learning activities in
order to complete each learning outcome of the module. In each learning
outcome there may be given Information Sheets, Self-Checks and Task
Sheets. Follow these activities on your own and answer the questions
that are given. Then, ask for the answer key from your instructor and
check your work honestly. If you have questions, please dont hesitate to
ask your facilitator for assistance.
This learning material was prepared to help you achieve the
required competency, in applying object-oriented program language
skills. This will be the source of information for you to acquire the
knowledge and skills in this particular module independently and at your
own pace with minimum supervision or help from your instructor.
In doing the activities to be completed as required in this module,
please be guided by the following:
Talk to your trainer and agree on how you will both organize in
taking this module. Read through the module carefully.
Work through all information and complete the activities in each
section. Read the information sheets and complete self-checks and task
checklist provided.
Most probably your trainer will also be your supervisor or
manager. He/she is there to support you and show you the correct way
to do things. Ask for help.
Your trainer will tell you about the important things you need to
consider when you are completing the activities and it is important that
you listen and take notes.
You will be given plenty of opportunities to ask questions and
practice on the job. Make sure you practice your new skills during
regular work shifts. This way you will improve both your speed and
memory and also your confidence.
Use the Self-Check, Job Sheets, Task Sheets at the end of each
section to test your own progress. Use the performance Criteria Checklist
or Procedural Checklist used after the sheet to check your own
performance.
When you feel confident that you have sufficient knowledge and
skills, ask your Trainer to evaluate you. The results of your assessment
will be recorded in your Progress Chart and Accomplishment Chart.
You need to complete this module before you can perform the next
module.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 3 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
UNIT OF COMPETENCY : Apply Object-Oriented Program
language skills

MODULE TITLE : Applying Object-Oriented Program


Language Skills

MODULE DESCRIPTION : This module defines the competency


required to undertake programming tasks
using an object oriented programming
language competence includes tool
usage, documentation, debugging and
testing techniques in support of the
programming activities

SUMMARY OF LEARNING OUTCOMES:

Upon completion of this module, the trainee/student must be able


to:

1. Apply basic language syntax and layout

2. Apply basic OO principles in the target language

3. Debug code

4. Document activities

5. Test code

ASSESSMENT CRITERIA:

1.1 Observed basic language syntax rules and best practice


based on program standard and structure.
1.2 Used language data types, operators and expressions based
on program standard and structure.
1.3 Used appropriate language syntax for sequence, selection
and iteration constructs based on program standard and
structure.
1.4 Used Arrays and array objects based on program standard
and structure.

2.1 Implemented a class that contains primitive member /


instance variables based on program structure.
2.2 Implemented a class that contains multiple options for object
construction based on program structure.
2.3 Defined aggregation in a class based on program structure.
2.4 Implemented inheritance to at least 2 levels of depth based
on program structure.
2.5 Used polymorphism at a simple level through inheritance to
enable easy code extension based on program structure.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 4 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
3.1 Used particularly an integrated development environment
and the language debugging facilities based on program
structure.
3.2 Used program debugging techniques to detect and resolve
errors based on program structure.

4.1 Used particularly an integrated development environment


and the language debugging facilities based on program
structure.
4.2 Used program debugging techniques to detect and resolve
errors based on program structure.

5.1 Developed and conducted simple test to confirm the coding


process to meet design specification
5.2 Documented the tests performed based on program and
documentation standard.
5.3 Made corrections to the code and documentation as needed.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 5 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
LEARNING OUTCOME #2 APPLY BASIC OO PRINCIPLES IN THE
TARGET LANGUAGE
CONTENTS:
Principles of Object oriented programming language
Encapsulation
Inheritance
Polymorphism
Form, Module, Class, and Objects
ASSESSMENT CRITERIA:
1. Implemented a class that contains primitive member / instance
variables based on program structure.
2. Implemented a class that contains multiple options for object
construction based on program structure.
3. Defined aggregation in a class based on program structure.
4. Implemented inheritance to at least 2 levels of depth based on
program structure.
5. Used polymorphism at a simple level through inheritance to
enable easy code extension based on program structure.
CONDITIONS:
The students/trainees must be provided with the following:
PC with OOPL
Manual / Printouts
Programming tools
ASSESSMENT METHODS:
Oral recitation
Written examinations
Case Study (Defence)

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 6 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Learning Experiences

Learning Outcome 2
Apply basic Object Oriented principles in the target language

Learning Activities Special Instructions


1. Read Information Sheet Read information sheet. After reading
3.2-1 Writing computer the learner is encourage to answer the
programs and defining OOP self-check.
2. Answer Self-Check 3.2-1 Compare answers to answer keys 3.2-1
3. Read Information Sheet Read information sheet. After reading
3.2-2 Writing computer the learner is encourage to answer the
programs and defining OOP self-check.
4. Answer Self-Check 3.2-2 Compare answers to answer keys 3.2-2

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 7 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Information Sheet 3.2-1
Writing computer programs and defining OOP

Learning Objective:

After reading this INFORMATION SHEET, YOU MUST be able to


identify the approaches in writing computer programs and define what
OOP is.

Programming Paradigm
There are two most common approaches to writing computer
programs.
These are:
Procedural programming
Object-oriented programming

Procedural programming is a style of programming in which the


programming task is broken down into a series of operations (called
procedures) applied to data (or data structures). Examples of procedural
programming languages are C and Pascal.

What is OOP?

On the other hand, object-oriented programming breaks down a


programming task into a series of interactions among different entities or
objects. This may be considered as an extension of procedural
programming in that the actions performed by each object are specified
by procedures. Examples of languages that support OOP are Java, C++,
and Smalltalk.

Object-oriented programming or OOP is a type of programming


in which programmers define not only the data structures, but also the
types of operations (methods) that can be applied to the data structure.
The data structure becomes an object that includes both data and
methods.

A major advantage of OOP is code reusability. OOP enables


programmers to create modules that do not need to be changed when a
new type of object is added. A new object can simply be created that
inherits many of its features from existing objects. This makes object-
oriented programs easy to understand and modify.
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, I will cite an example (refer to


figure 1.1). 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 cars data, including direction,
position, and speed.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 8 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Figure 1.1

When you travel in a car, however, you dont have to know the
details of how these operations work. To stop a car, for example, you
simply step on the brake pedal. You dont 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. Youre not likely
to confuse a car with a dishwasher, tree, or playground. A car is a
complete unit an object with unique properties.

OOP has the following advantages over conventional approaches:


It provides a clear modular structure for programs which makes it
good for defining abstract data types where implementation details
are hidden and the unit has a clearly defined interface.
It makes it easy to maintain and modify existing code as new
objects can be created with small differences from existing ones.
It provides a good framework for code libraries where supplied
software components can be easily adapted and modified by the
programmer. This is particularly useful for developing graphical
user interfaces.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 9 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
SELF-CHECK 3.2-1

MULTIPLE CHOICE
Direction: Choose the correct answer from the choices given. Write
your answer in your answer sheet.

1. It is a style of programming in which the programming task is broken


down into a series of operations

a. Procedural Programming c. Scripting


b. Object-Oriented Programming d. Special Scripting

2. All are programming languages use for implementing OOP approach


except.

a. JAVA c. C
b. C++ d. Smalltalk

3. The ______________ becomes an object that includes both data and


methods.

a. Object c. Method
b. Data Structure d. Procedure

4. It is a style of programming that breaks down a programming task


into a series of interactions among different entities or objects.

a. Procedural Programming c. Scripting


b. Object-Oriented Programming d. Special Scripting

5. It is a major advantage of Object Oriented Programming?

a. Code Wise c. Code Base


b. Code Reusability d. Hard Coding

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 10 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Answer Key 3.2-1

Multiple Choice

1. A
2. C
3. B
4. B
5. B

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 11 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Information Sheet 3.2-2
Concepts of OOP

Learning Objective:

After reading this INFORMATION SHEET, YOU MUST be able to


describe each key concept of OOP.

Object-oriented programming enables you to think of program elements


as objects. The six key concepts of OOP include:
Objects
Classes
Abstraction
Inheritance
Encapsulation
Polymorphism

Objects and Classes

The two most important concepts in object-oriented programming


are the class and the object. In its simplest form, an object is anything
that models things in the real world. These things may be physical
entities such as cars, or events such as a concert, or abstractions such
as a general-purpose account. Objects are made up of attributes and
methods.

Attributes are the characteristics that define an object. The


attributes of an object are also referred to as its states. They
differentiate objects of the same class type. For example, your cars
attributes include its make, model, year, and purchase price. All cars
can possess the same attributes, but not necessarily the same values
for all those attributes.

Aside from attributes, objects have abilities or methods. Objects


use these methods to accomplish tasks. Programmatically, a method is
a self-contained block of program code that is similar to a procedure or
function. For example, a car can move forward and backward, can be
filled with gasoline, or be washed. Methods can also ascertain
attributes, such as the current speed of a car and the current status of
its gas tank (how much gas it contains). Different cars may have
different ways of performing these abilities.

As an analogy, in grammar, a noun is equivalent to an object and


an adjective is an attribute, and verbs are methods. A class is a term
that describes a group or collection of objects with common properties
(both attributes and methods).

A class is an abstract description of an object a general plan or


blueprint for an object. An object is created from a class by a process
called instantiation. An object is then said to be an instance of a class.
Thus, your blue Honda Car with the dent can be considered an
instance of the class that is made up of all cars.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 12 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
The class implementation specifies the data structure for each of its
objects. For example (refer to figure 1.2), 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.

Exemptions
Hire
Position Promote
Salary Change phone
Phone extension Extension

Figure 1.2

Abstraction
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 (Figure 1.3), 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).

Figure 1.3

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 13 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Encapsulation

Encapsulation refers to the hiding of data (attributes) and methods


within an object. It protects an objects 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 objects data
from arbitrary and unintended use.

Encapsulation also hides the details of an objects internal


implementation from the users of an object. Users understand what
operations (methods) may be requested of the object but, in most cases,
need not know the details of how the operation is performed. All the
specifics of the objects data and the coding of its operations are tucked
out of sight.

Encapsulation is important, because it separates how an object


behaves from how it is implemented. This allows object implementations
to be modified without requiring the applications that use them to be
modified also.

It is easier to modify programs using encapsulation, because one


object type is modified at a time. If an object type is changed, only the
operations and data structures associated with that object type are
affected and usually only some of those operations and data structures.
The object types behavior can be changed and tested, independently of
other object types.

Illustration of encapsulation
Figure 1.4

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 14 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
The (Figure 1.4) illustrated a good visualization on what
encapsulation is all about. It gives the programmer a freedom to combine
attributes (variables) and methods into a single logical unit. The
programmer will be able to simply declare a simple identifier having the
ability to summon methods and change the value of variables (attributes)
within them. For example, the user does not need to know how the name
is stored internally. The user just needs to know the limitations, e.g.,
what characters are acceptable and how long the name can be. The
programmer can then later implement a data compression method on the
name to reduce the storage space used just keeping in mind the agreed
limitations on the name.

Inheritance

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
Figure 1.5

Another example (Figure 1.5) would be a Student class having


Name and Student ID as its attributes and getID(), getName(), setID()
and setName() as its methods. We can assume that a student will

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 15 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
eventually become a graduate student. Therefore, a graduate student
class can be created from the Student class. When the class Student is
inherited, its attributes and methods will then be copied into the
inheriting class.

Polymorphism

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.

One of the strength of polymorphism is that a request for an


operation can be made without knowing which specific method should be
invoked. These implementation details are hidden from the user. Instead,
the responsibility rests with the selection mechanism of the Object
Oriented implementation.

Illustration of polymorphism
Figure 1.6

In the given figure (refer to Figure 1.6), 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.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 16 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Abstract Classes

An abstract class is a class that is not used to create (instantiate)


objects. It is designed to act as a base class (to be inherited by other
classes). The abstract class is a design concept in program development
and provides a base upon which other classes are built. After declaring
an abstract class, it cannot be instantiated on its own. It must be used in
creating new classes making its members (attributes and methods)
inherited. Abstract classes can only specify members that should be
implemented by all inheriting classes.

For example (refer to Figure 1.7), 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.

Illustration of Abstract Class


Figure 1.7

Interfaces

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.

In simple terms, an interface just specifies what methods should


be defined in a class that implements the interface. A class implementing
an interface will then have to define all the methods specified by the
interface.

Inheritance

As discussed in the previous topic, inheritance is the capability of


a class to use the properties and methods of another class while adding
its own functionality. The ability to use inheritance in Java makes
programs easier to write, less error-prone, and more quickly understood.

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 17 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
The class that is used to define a new class is called a parent class
(or superclass or base class). A class created to inherit from a base class
is called a child class (or subclass or derived class) (of the parent class, in
particular). A subclass inherits all the members (fields, methods, and
nested classes) of its superclass.
Note that constructors are not members, so these are not inherited
by subclasses. However, the constructor of the superclass can be
invoked from the subclass.

There are three sets of phrases used to describe the inheritance


relationship: parent/child, base class/derived class, and
superclass/subclass. These are illustrated in the (Figure 1.8).

Sets of phrases to describe the inheritance relationship


Figure 1.8

In some Object Oriented Programming Languages, all classes are


subclassed from the Object superclass. Below is a figure that illustrates
a sample class hierarchy (refer Figure 1.9):

Object class hierarchy


Figure 1.9

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 18 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
The benefit of using inheritance in OOP is reusability. Once a
behavior (method) is defined in a superclass, that behavior is
automatically inherited by all subclasses. Therefore, you can encode a
method only once and they can be used by all subclasses. A subclass
only needs to implement its differences with its parent.

SELF-CHECK 3.2-2

MULTIPLE CHOICE
Direction: Choose the correct answer from the choices given. Write
your answer in your answer sheet

1. Is the capability of a class to use the properties and methods of


another class while adding its own functionality?

a. Encapsulation c. Abstract Classes


b. Inheritance d. Object

2. Allow you to create definitions for component interaction?

a. Interfaces c. Polymorphism
b. Class d. Abstraction

3. Refers to the ability to process objects differently depending on their


data type or class.

a. Interfaces c. Polymorphism
b. Class d. Constructor

4. Is a class that is not used to create (instantiate) objects. It is


designed to act as a base class (to be inherited by other classes)?

a. Encapsulation c. Abstract Classes


b. Inheritance d. Object

5. 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. Constructor b. Object
c. Interfaces d. Abstraction

6. A __________ is an abstract description of an object a general plan


or blueprint for an object?

a. Interfaces c. Inheritance
b. Class d. Object

7. Are not members, so these are not inherited by subclasses. However,


the superclass can be invoked from the subclass?

a. Encapsulation c. Abstract Classes


b. Inheritance d. Constructor

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 19 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
8. Refers to the hiding of data (attributes) and methods within an
object?

a. Encapsulation c. Abstract Classes


b. Inheritance d. Object

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 20 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills
Answer Key 3.2-2

Multiple Choice

1. B
2. A
3. C
4. C
5. D
6. B
7. D
8. A

Programming NC Document No.


STI IV Developed: Issued by:
QA Edryl P. Ugpo
Apply Object- Date Page 21 of 21
SYSTEM Revision #___
Oriented Program April 2012
Language Skills

Das könnte Ihnen auch gefallen