By the end of this chapter, you will be able to:
These skills will help you create software that truly fits what users want, making you a valuable programmer in the real world!
Compiled by: Ann Chebet
Object Oriented Programming (OOP) forms a cornerstone of modern software development, enabling programmers to create modular, reusable, and maintainable code. In the Kenyan software industry, where diverse applications from banking systems to mobile platforms are rapidly evolving, mastering OOP principles is essential for delivering robust solutions. This chapter focuses on applying programming skills by exploring programming language types, criteria for language selection, and practical exercises involving class creation and collaborative development. These competencies prepare software developers to work effectively both individually and in teams, reflecting real-world software engineering practices.
Programming languages are the tools through which a developer turns human logic into instructions a computer can run. Languages differ in the way they ask the programmer to organise a program, in their syntax and in the environment where the finished program runs. A developer who understands these differences can choose a suitable language for work as varied as a stock-keeping app for a hardware shop, a booking system for a salon or firmware for a small device.
A programming language category groups languages by the main way they ask you to describe a computation. This unit covers three categories: procedural, object-oriented and functional. The same small job is solved in each of them below so that the differences can be seen in working code.
The job: a hardware shop order has three lines. Each line has a quantity and a unit price in Ksh: 4 items at 250, 10 items at 35 and 2 items at 1,200. The program must print the order total.
Line totals: 4 × 250 = 1,000; 10 × 35 = 350; 2 × 1,200 = 2,400.
Order total: 1,000 + 350 + 2,400 = 3,750.
Many languages belong to more than one category. Python, JavaScript and C++ let a programmer write in several styles, and Java now includes functional features. A language is placed in the category whose ideas shaped its design. The topic Programming Paradigms looks at the same styles as ways of thinking about a program.
A procedural language organises a program as a sequence of instructions grouped into procedures, also called functions or subroutines. The programmer writes the steps in order, keeps data in variables and arrays, and calls procedures to carry out repeated work. The program state changes as variables are updated step by step.
Main features:
Typical languages are C, Pascal, Fortran and COBOL. C is widely used for operating system components, device drivers and the firmware inside embedded devices.
The order total in C:
#include <stdio.h>
double line_total(int quantity, double unit_price) {
return quantity * unit_price;
}
int main(void) {
int quantities[] = {4, 10, 2};
double prices[] = {250.0, 35.0, 1200.0};
double total = 0.0;
for (int i = 0; i < 3; i++) {
total += line_total(quantities[i], prices[i]);
}
printf("Total: Ksh %.2f\n", total);
return 0;
}
Output:
Total: Ksh 3750.00
The loop visits the three positions of the arrays. The procedure line_total returns 1000.0, then 350.0, then 2400.0, and total grows to 3750.0.
Strengths and limits:
An object-oriented language organises a program around objects. An object bundles data, called attributes or fields, with the procedures that work on that data, called methods. Objects are created from classes, and the program runs as objects send messages to each other by calling methods.
Main features:
Java, C# and Kotlin are designed around classes. C++ and Python support classes alongside other styles. The later topics Implementing Objects and Classes, Applying Object Encapsulation, Implementing Class Inheritance and Implementing Polymorphism teach these ideas in full.
The order total in Java:
public class Order {
public static void main(String[] args) {
OrderLine[] lines = {
new OrderLine(4, 250.0),
new OrderLine(10, 35.0),
new OrderLine(2, 1200.0)
};
double total = 0.0;
for (OrderLine line : lines) {
total += line.total();
}
System.out.printf("Total: Ksh %.2f%n", total);
}
}
class OrderLine {
private final int quantity;
private final double unitPrice;
OrderLine(int quantity, double unitPrice) {
this.quantity = quantity;
this.unitPrice = unitPrice;
}
double total() {
return quantity * unitPrice;
}
}
Output:
Total: Ksh 3750.00
Each OrderLine object holds its own quantity and price and knows how to calculate its own total. The main method no longer handles two parallel arrays: it asks each object for its total and adds the results, 1000.0 + 350.0 + 2400.0 = 3750.0.
Strengths and limits:
A functional language treats computation as the evaluation of functions. A function takes values in and gives a value out, and a pure function does nothing else: it does not change a variable outside itself and gives the same result every time for the same input. Functions are values too, so one function can be passed to another.
Main features:
Typical languages are Haskell, Erlang, Elixir, OCaml, F# and Clojure. Erlang was designed for telecommunication systems that keep very many separate activities running at once. JavaScript, Python and Java are not purely functional, but each lets a programmer use a functional style.
The order total in Haskell:
orderTotal :: [(Int, Double)] -> Double
orderTotal orderLines = sum (map lineTotal orderLines)
where
lineTotal (quantity, price) = fromIntegral quantity * price
main :: IO ()
main = putStrLn ("Total: Ksh " ++ show (orderTotal [(4, 250), (10, 35), (2, 1200)]))
Output:
Total: Ksh 3750.0
The program has no loop and no variable that changes. The function map applies lineTotal to each pair, giving the list [1000.0, 350.0, 2400.0], and sum adds the list to 3750.0. The function fromIntegral converts the whole-number quantity to a decimal number so it can be multiplied by the price.
Strengths and limits:
Choosing a language starts with the user's requirements, then moves to the project's size, the speed needed, the team's skills, the target platform and the support available. A poor choice shows up later as slow programs, missed deadlines or code nobody can maintain, so a developer weighs these criteria before writing any code.
A large system with many features and several developers benefits from a language with strong support for modular design, such as Java or C#. A small automation job, such as renaming files or producing a nightly stock report, is better served by Python or Bash because the code is short and quick to write.
Programs that need high speed and low delay, such as firmware in a device or the engine of a game, are usually written in compiled languages such as C or C++. A website or a business app that must be built quickly can use a dynamic language such as JavaScript or Python, accepting slower execution in exchange for faster development.
A team's familiarity with a language affects its productivity and the quality of its code. A software team that already works well in Python may choose it for a new project to use its existing skills and avoid the cost of training.
The target platform limits the choice. Android apps are written mainly in Kotlin or Java, and iPhone apps in Swift or Objective-C. Cross-platform frameworks use JavaScript or Dart. A developer finds out where the client's users will run the software before selecting a language.
A language with an active community offers many libraries, frameworks and tools, and answers to common problems are easy to find. Python's libraries for data analysis and machine learning are an example of an ecosystem that can shorten a project.
Example: the owner of a hardware shop asks for two things: a stock app that staff use on Android phones, and a nightly script that totals the day's sales into a report. For the app, platform compatibility points to Kotlin or Java. For the script, project size and speed of writing point to Python. The same client therefore receives two programs in two languages, each chosen for its own requirement.
Create a free account to open more of this chapter.
Free: practical guides, quick cards, workplace scenarios and more.
Create a free accountThis chapter explored various programming language types, highlighting procedural, object-oriented, and functional categories, and discussed how to select a language based on specific user requirements. It then examined common programming paradigms, including imperative and declarative approaches, emphasizing the importance of choosing the right paradigm to suit project needs. The program development life cycle was described with its key stages such as planning, design, and implementation, alongside best practices for adapting these stages to different work contexts. Design tools like algorithms, flowcharts, wireframes, pseudocode, and decision tables were introduced, with guidance on selecting appropriate tools depending on project complexity and user requirements. The chapter also covered program writing tools and integrated development environments, evaluating options like Visual Studio and Eclipse based on system needs and developer preferences. Practical skills were reinforced through activities involving creating simple classes, instantiating objects, and engaging in collaborative projects where team members implement different classes from a shared design. Together, these topics provide a comprehensive foundation for applying computer programming skills effectively.
Which of the following best describes a procedural programming language? (2 marks)
a) Focuses on objects and their interactions
b) Executes instructions sequentially using procedures or routines
c) Emphasizes immutability and pure functions
d) Uses declarative statements to define logic
Identify two key differences between object-oriented and functional programming paradigms. (4 marks)
Type: Individual
| Tools & Equipment | Materials |
|---|---|
| Computer with Windows 7 OS or higher | List of programming languages for classification |
| Installed Java Development Kit (JDK) | Printed classification table template |
| NetBeans or Eclipse IDE | |
| Flash disk or CD RW |
| S/N | Item | Quantity |
|---|---|---|
| 1 | Computer with Windows 7 OS or higher | 1 Pc per Candidate |
| 2 | Installed Java Development Kit (JDK) | 1 Pc per Candidate |
| 3 | NetBeans or Eclipse IDE | 1 Pc per Candidate |
| 4 | Flash disk or CD RW | 1 Pc per Candidate |
| 5 | List of programming languages for classification | 1 Set per Candidate |
| 6 | Printed classification table template | 1 Sheet per Candidate |
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|---|---|---|
| TASK 1: Identify Programming Language Types | |||
| Candidate reads and understands the list of programming languages (Award 2 marks for correctly identifying all languages) | 2 | ||
| Candidate uses IDE or notes to research language types if unsure (Award 2 marks for effective use of IDE or research) | 2 | ||
| Candidate classifies each language into correct category: Procedural, Object-Oriented, or Functional (Award 1 mark per correctly classified language, total 6 marks) | 6 | ||
| Sub-Total | 10 | ||
| TASK 2: Document Classification Results | |||
| Candidate fills the classification table template neatly and legibly (Award 3 marks for clear and complete documentation) | 3 | ||
| Candidate saves and backs up the completed classification table on flash disk (Award 2 marks for correct saving and backup) | 2 | ||
| Sub-Total | 5 | ||
| PRODUCT CHECKLIST | |||
| Classification table accurately lists languages under correct categories (Procedural, Object-Oriented, Functional) (Award up to 10 marks for accuracy and completeness of classification) | 10 | ||
| Classification table is neat, legible, and properly formatted on A4 sheet (Award up to 5 marks for presentation and formatting) | 5 | ||
| Sub-Total | 15 | ||
| GRAND TOTAL | 30 | ||
Type: Individual
| Tools & Equipment | Materials |
|---|---|
| Computer installed with Windows 10 OS or higher | Flash disk |
| Internet access for research | |
| Office suite software (Word Processor, Spreadsheet) |
| S/N | Item | Quantity |
|---|---|---|
| 1 | Computer installed with Windows 10 OS or higher | 1 Pc per Candidate |
| 2 | Internet access for research | 1 Pc per Candidate |
| 3 | Office suite software (Word Processor, Spreadsheet) | 1 Pc per Candidate |
| 4 | Flash disk | 1 Pc per Candidate |
| Items to be Evaluated | Marks Available | Marks Obtained | Comments |
|---|---|---|---|
| TASK 1: Analyze user requirements | |||
| Identified and listed user requirements clearly (Award 3 marks for clear, complete listing of requirements or 0) | 3 | ||
| Researched programming languages suitable for the requirements (Award 4 marks for thorough research covering at least 3 languages or 0) | 4 | ||
| Evaluated languages against criteria such as performance, ease of use, platform compatibility, and community support (Award 5 marks for detailed evaluation with relevant criteria or 0) | 5 | ||
| Sub-Total | 12 | ||
| TASK 2: Select and justify programming language | |||
| Selected the most appropriate programming language based on analysis (Award 5 marks for a justified, logical selection or 0) | 5 | ||
| Prepared a written report with clear reasoning and supporting facts (Award 6 marks for a well-structured report with justification or 0) | 6 | ||
| Included recommendations for future scalability and maintenance (Award 4 marks for relevant recommendations or 0) | 4 | ||
| Sub-Total | 15 | ||
| TASK 3: Present deliverable | |||
| Formatted report professionally with headings and bullet points (Award 3 marks for professional formatting or 0) | 3 | ||
| Saved and submitted report on flash disk in Word or PDF format (Award 2 marks for correct file format and submission or 0) | 2 | ||
| Sub-Total | 5 | ||
| PRODUCT CHECKLIST | |||
| Report contains all required sections: user requirements, language options, evaluation, selection, justification, and recommendations (Award 8 marks for complete, coherent report or 0) | 8 | ||
| Report length approximately 1000 words (Award 4 marks for meeting length requirement or 0) | 4 | ||
| Report free from spelling and grammatical errors (Award 3 marks for error-free writing or 0) | 3 | ||
| Sub-Total | 15 | ||
| GRAND TOTAL | 47 | ||
At the start of this chapter we promised you would be able to:
Tick each one you can genuinely do.
So, are you there yet?
You're competent when you can confidently do 50% or more of what this chapter promised.
Sign in to record how you're doing.