Saqa 14909 - Learner Guide
Saqa 14909 - Learner Guide
Saqa 14909 - Learner Guide
LEARNER GUIDE
SAQA: 14909
1|Page
Learner Information:
Details Please Complete this Section
Name & Surname:
Organisation:
Unit/Dept:
Facilitator Name:
Date Started:
Date of Completion:
Copyright
All rights reserved. The copyright of this document, its previous editions and any
annexures thereto, is protected and expressly reserved. No part of this
document may be reproduced, stored in a retrievable system, or transmitted, in
any form or by any means, electronic, mechanical, photocopying, recording or
otherwise without the prior permission.
2|Page
Key to Icons
The following icons may be used in this Learner Guide to indicate specific
functions:
This icon means that other books are available for further
information on a particular topic/subject.
Books
References
3|Page
Tasks/Projects
This icon indicates practical tips you can adopt in the future.
Tips
4|Page
Learner Guide Introduction
About the Learner This Learner Guide provides a comprehensive overview of the
Guide… Describe the difference between programming in Object
Orientated and Procedural Languages,and forms part of a series
of Learner Guides that have been developed for FURTHER
EDUCATION AND TRAINING CERTIFICATE: INFORMATION
TECHNOLOGY: SYSTEMS DEVELOPMENT ID 78965 LEVEL 4 –
CREDITS 165 The series of Learner Guides are conceptualized in
modular’s format and developed FURTHER EDUCATION AND
TRAINING CERTIFICATE: INFORMATION TECHNOLOGY: SYSTEMS
DEVELOPMENT ID 78965 LEVEL 4 – CREDITS 165They are designed
to improve the skills and knowledge of learners, and thus
enabling them to effectively and efficiently complete specific
tasks. Learners are required to attend training workshops as a
group or as specified by their organization. These workshops are
presented in modules, and conducted by a qualified facilitator.
5|Page
are required to perform tasks on the job to collect enough and
appropriate evidence for their portfolio of evidence, proof
signed by their supervisor that the tasks were performed
successfully.
To qualify To qualify and receive credits towards the learning programme,
a registered assessor will conduct an evaluation and assessment
of the learner’s portfolio of evidence and competency
Range of Learning This describes the situation and circumstance in which
competence must be demonstrated and the parameters in
which learners operate
Responsibility The responsibility of learning rest with the learner, so:
• Be proactive and ask questions,
• Seek assistance and help from your facilitators, if required.
6|Page
Describe the difference between
1
programming in Object Orientated and
Procedural Languages
Learning Unit
The credit value of this unit is based on a person having the prior knowledge and skills to:
be able to apply the principles of Procedural Computer Programming
7|Page
SESSION 1.
Learning Outcomes
• 1.The description explains the basic principles of a class.
• 2. The description explains the basic principles of an object.
• 3. The description explains the basic principles of information hiding and
encapsulation
• 4. The Description explains the basic principles of inheritance.
• 5. The Description explains the principles of polymorphism.
Introduction
Object-oriented programming
Object-oriented programming is a programming paradigm that uses abstraction to
create models based on the real world. It uses several techniques from previously
established paradigms, including modularity, polymorphism, and encapsulation. Today,
many popular programming languages (such as Java, JavaScript, C#, C++, Python,
PHP, Ruby and Objective-C) support object-oriented programming (OOP).Object-
oriented programming may be seen as the design of software using a collection of
cooperating objects, as opposed to a traditional view in which a program may be seen
as a collection of functions, or simply as a list of instructions to the computer. In OOP,
each object is capable of receiving messages, processing data, and sending messages
to other objects. Each object can be viewed as an independent little machine with a
distinct role or responsibility. Object-oriented programming is intended to promote
greater flexibility and maintainability in programming, and is widely popular in large-
scale software engineering. By virtue of its strong emphasis on modularity, object
oriented code is intended to be simpler to develop and easier to understand later on,
8|Page
lending itself to more direct analysis, coding, and understanding of complex situations
and procedures than less modular programming methods.2
Terminology
Class
Defines the characteristics of the Object.
Object
An Instance of a Class.
Property
An Object characteristic, such as color.
Method
An Object capability, such as walk.
Constructor
A method called at the moment of instantiation.
Inheritance
A Class can inherit characteristics from another Class.
Encapsulation
9|Page
A Class defines only the characteristics of the Object, a method defines only how the
method executes.
Abstraction
The conjunction of complex inheritance, methods, properties of an Object must be
able to simulate a reality model.
Polymorphism
Different Classes might define the same method or property.
12 | P a g e
• A class is a pattern, template, or
blueprint for a category of structurally
identical items. The items created using
the class are called instances. This is
often referred to as the "class as a
`cookie cutter'" view. As you might
guess, the instances are the "cookies."
• A class is a thing that consists of both a
pattern and a mechanism for creating
items based on that pattern. This is the
"class as an `instance factory'"
view; instances are the individual items
that are "manufactured" (created) using
the class's creation mechanism.
• A class is the set of all items created
using a specific pattern. Said another
way, the class is the set of
all instances of that pattern.
In this article, we will use the definition of a "class an `instance factory.'"
We should note that it is possible for an instance of a class to also be a class.
A metaclass is a class whose instances themselves are classes. This means when we use
the instance creation mechanism in a metaclass, the instance created will itself be a
class. The instance creation mechanism of this class can, in turn, be used to create
instances -- although these instances may or may not themselves be classes.
A concept very similar to the metaclass is the parameterized class. A parameterized
class is a template for a class wherein specific items have been identified as being
required to create non-parameterized classes based on the template. In effect, a
parameterized class can be viewed as a "fill in the blanks" version of a class. One
cannot directly use the instance creation mechanism of a parameterized class. First, we
must supply the required parameters, resulting in the creation of a non-parameterized
13 | P a g e
class. Once we have a non-parameterized class, we can use its creation mechanisms
to create instances. In this article, we will use the term "class" to mean metaclass,
parameterized class, or a class that is neither a metaclass nor a parameterized class.
We will make a distinction only when it is necessary to do so. Further, we will
occasionally refer to "non-class instances." A non-class instance is an instance of a
class, but is itself not a class. An instance of a metaclass, for example, would not be a
non-class instance.
In this article, we will sometimes refer to "instantiation." Instantiation has two common
meanings:
• as a verb, instantiation is the process of creating an instance of a class, and
• as a noun, an instantiation is an instance of a class.
Some people restrict the use of the term "object" to instances of classes. For these
people, classes are not objects. However, when these people are confronted with the
concepts of metaclasses and parameterized classes, they have a difficulty attempting
to resolve the "problems" these concepts introduce. For example, is a class that is an
instance of a metaclass an object -- even though it is itself a class? In this article, we will
use the term "object" to refer to both classes and their instances. We will only distinguish
between the two when needed.
Black Boxes and Interfaces
Objects are "black boxes." Specifically, the underlying implementations of objects are
hidden from those that use the object. In object-oriented systems, it is only the producer
(creator, designer, or builder) of an object that knows the details about the internal
construction of that object. The consumers (users) of an object are denied knowledge
of the inner workings of the object, and must deal with an object via one of its three
distinct interfaces:
• the "public" interface. This is the interface that is open (visible) to everybody.
• the "inheritance" interface. This is the interface that is accessible only by direct
specializations of the object. (We will discuss inheritance and specialization later in
this chapter.) In class-based object-oriented systems, only classes can provide an
inheritance interface.
14 | P a g e
• the "parameter" interface. In the case of parameterized classes, the parameter
interface defines the parameters that must be supplied to create an instance of the
parameterized class.
Another way of saying that an item is in the public interface of an object is to say that
the object "exports" that item. Similarly, when an object requires information from
outside of itself (e.g., as with the parameters in a parameterized class), we can say that
the object needs to "import" that information.
17 | P a g e
device." Therefore, a television set is a product
of multiple inheritance.
Inheritance
One important characteristic of object-oriented languages is
inheritance. Inheritance refers to the capability of defining a new class of objects that
inherits from a parent class. New data elements and methods can be added to the
new class, but the data elements and methods of the parent class are available for
objects in the new class without rewriting their declarations.
For example, Java uses the following syntax for inheritance:
public class B extends A {
declarations for new members
}
Objects in class B will have all members that are defined for objects in class A. In
addition, they have the new members defined in the declaration of class B.
The extends keyword signals that class B inherits from class A. We also say that B is
a subclass of A and that A is the parent class of B.
In some languages, Java for example, the programmer has some control over which
members are inherited. In Java, a member is defined with a keyword indicating its level
of accessibility. The keyword private indicates that the member is not inherited by
subclasses. This capability is not often used.
[an error occurred while processing this directive]
}
Each object in the class will have all members defined in the declarations.
Class Members and Instance Members
In many object-oriented languages, classes are objects in their own right (to a greater
or lesser extent, depending on the language). Their primary function is as factories for
objects in the category. A class can also hold data variable and constants that are
shared by all of its objects and can handle methods that deal with an entire class rather
than an individual object. These members are called class members or, in some
19 | P a g e
languages (C++ and Java, for example), static members. The members that are
associated with objects are called instance members.
SESSION 2.
Learning Outcomes
• 1. The description explains the use of functions and variables in structure
programming, using simple examples.
20 | P a g e
• 2. The description compares encapsulation of data and functions in objects versus
procedural programming
• 3. The Description identifies possible classes for simple examples.
Procedural programming
In procedural programing our code is organised into small "procedures" that use and
change our data. In ColdFusion, we write our procedures as either custom tags or
functions. These functions typically take some input, do something, then produce some
output. Ideally your functions would behave as "black boxes" where input data goes in
and output data comes out. The key idea here is that our functions have no intrinsic
relationship with the data they operate on. As long as you provide the correct number
and type of arguments, the function will do its work and faithfully return its output.
Sometimes our functions need to access data that is not provided as a parameter, i.e.,
we need access data that is outside the function. Data accessed in this way is
considered "global" or "shared" data.
21 | P a g e
So in a procedural system our functions use data they are "given" (as parameters) but
also directly access any shared data they need.
Object oriented programming
In object oriented programming, the data and related functions are bundled together
into an "object". Ideally, the data inside an object can only be manipulated by calling
the object's functions. This means that your data is locked away inside your objects and
your functions provide the only means of doing something with that data. In a well
designed object oriented system objects never access shared or global data, they are
only permitted to use the data they have, or data they are given.
In an object oriented system we know that all variables are inside objects and that only
functions within those objects can access or change those variables. When a variable
needs to be changed then we only need to change the functions that access those
variables. As long as we take care that the functions' input arguments and output types
are not changed, then we don't need to change any other part of the system.
23 | P a g e
The cost of OO
Object oriented design is complicated to do well, and a substantial amount of time is
likely to be required to learn it in depth. If you have been developing procedural
systems for some time then object oriented concepts will require learning a different
way of thinking which is always challenging and requires effort. However the time to
learn is not the only cost. Once you start learning, you may start to question yourself
time and time again if you are writing code "correctly". Your productivity may be
affected as you try different ideas, aiming for a good object oriented solution. A further
cost to consider is not specific to OO, but is specific to OO within ColdFusion. You may
read many object oriented articles and books but you cannot apply their teachings
blindly in your ColdFusion applications. There is a performance factor associated with
creating objects in ColdFusion so applying many of the pure object oriented ideas can
adversely affect your application. This then adds an additional challenge in knowing
when not to apply some object oriented ideas.
A Real-World Example
Okay, that's enough theory. We're going to put both types of programming to the test
with a real-world example. Let's say that you are working for a vehicle parts
manufacturer that needs to update its online inventory system. Your boss tells you to
24 | P a g e
program two similar but separate forms for a website, one form that processes
information about cars and one that does the same for trucks.
For cars, we will need to record the following information:
• Color
• Engine Size
• Transmission Type
• Number of doors
For trucks, the information will be similar, but slightly different. We need:
• Color
• Engine Size
• Transmission Type
• Cab Size
• Towing Capacity
In procedural programming, you would write the code first to process the car form and
then the code for the truck form. With object-oriented programming, you would write a
base class called vehicle that would record the common characteristics what we need
from both trucks and cars. In this case, the vehicle class will record:
• Color
• Engine Size
• Transmission Type
We'll make each one of those characteristics into a separate method. The color
method, for example, could take the color of the vehicle as a parameter and do
something with it, like storing it in a database. Next, we will create two more classes:
truck and car, both of which will inherit all of the methods of the vehicle class and
extend it with methods that are unique to them. The car class will have a method
called number Of Doors and the truck class will have the methods cab Size and towing
Capacity. Okay, so let's assume that we have a working example for both procedural
and OO programming. Now, let's run through a few scenarios that we could come
across in a normal working environment. You know the type of scenario because it
25 | P a g e
always begins with the thought: I really wish my boss didn't send this in an email request
at 4pm on a Friday afternoon.
Scenario 1
Suppose that we suddenly need to add a bus form, that records the following
information:
• Color
• Engine Size
• Transmission Type
• Number of passengers
Procedural: We need to recreate the entire form, repeating the code for Color, Engine
Size, and Transmission Type.
OOP: We simply extend the vehicle class with a bus class and add the method, number
Of Passengers.
Scenario 2
Instead of storing color in a database like we previously did, for some strange reason
our client wants the color emailed to him.
Procedural: We change three different forms: cars, trucks, and buses to email the color
to the client rather than storing it in the database.
OOP: We change the color method in the vehicle class and because the car, truck,
and bus classes all extend (or inherit from, to put it another way) the vehicle class, they
are automatically updated.
Scenario 3
We want to move from a generic car to specific makes, for example: Nissan and
Mazda.
Procedural: We create a new form for each make, repeating all of the code for
generic car information and adding the code specific to each make.
OOP: We extend the car class with a nissan class and a mazda class and add methods
for each set of unique information for that car make.
Scenario 4
We found a bug in the transmission type area of our form and need to fix it.
26 | P a g e
Procedural: We open and update each form.
OOP: We fix the transmission Type method in the vehicle class and the change
perpetuates in every class that inherits from it.
Wrapping It Up
As you can see from the above scenarios, employing an OOP style has significant
advantages over procedural programming, especially as your scale increases.
Consider the savings we would receive from OOP in terms of repeated code, flexibility,
and maintenance if we also had to add forms for boats, motorcycles, planes, go-karts,
ATVs, snowmobiles, etc. Objects and methods are also far easier to test than
procedural programming by using unit testing to test results. Does this mean that you
should never use procedural programming? Not necessarily. If you're doing a mockup
or a proof-of-concept app, you might not have the time to make everything object-
oriented and so I think it might would be better to use procedural programming for a
prototype, but it would be best to make the production product in an OO-manner.
This has been just a brief foray into a very large subject, but I hope that you've been
able to get a better understanding of procedural vs. object-oriented programming and
when and how to use each. If this tutorial has been helpful to you, please bookmark it
for your reference and share it with your friends and colleagues.
• Procedural Programming
– top down design
– create functions to do small tasks
– communicate by parameters and return values
28 | P a g e