1 Introduction To Object Oriented Programming

Object Oriented Programming · Unit 1 · 3 hrs

Introduction to Object Oriented Programming

Exam-focused notes for Introduction to Object Oriented Programming (Object Oriented Programming, CSC166): what the TU syllabus asks and how it has actually been tested, with 4 solved past questions from this unit.

Introduction to Object Oriented Programming in short

This unit contrasts the structured (procedure oriented) style of programming with the object oriented style that C++ is built around, then works through the core vocabulary of object oriented languages: objects, classes, encapsulation, inheritance, polymorphism and dynamic binding, that recur through every later unit.

Introduction to Object Oriented Programming: notes

Overview of structured programming approach

Structured programming, also called procedure oriented programming, organizes a program as a collection of functions, each performing one well defined task, with control flowing from the top of the program down through these functions. It rests on a few consistent ideas. Emphasis falls on the algorithm rather than on the data: the programmer designs the sequence of steps first and only afterward decides what variables carry the data between them. A large program is divided into smaller, more manageable units called functions, and most of the data those functions work on is kept as global variables, so that many functions can read and change it directly. The design proceeds top down, breaking the overall task into sub tasks and those sub tasks into still smaller ones, and data therefore moves openly around the system from function to function, each function's job being to transform that data from one form into another.

This style works well for programs of moderate size, and languages such as C, FORTRAN and Pascal are built around it, but it has two weaknesses that become serious as a program grows. Because data is global, if the layout of a data structure has to change, every function that touches that structure has to be revised, and in a large program it is easy to miss one. And because functions are organized around actions rather than around the things a program models, procedural code does not map cleanly onto real world entities: a banking program written this way ends up with functions like deposit() and withdraw() floating free, rather than an Account that owns its own balance together with the operations allowed on it.

What this unit covers

  • Overview of structured programming approach
  • Object oriented programming approach
  • Characteristics of object oriented languages

Characteristics of object oriented languages

2079 · 5 marks

Describe the characteristics of object oriented programming languages. [5]

Object-Oriented Programming (OOP) is a programming paradigm that organizes software design around objects rather than functions and logic. The key characteristics (terms) of OOP are described below: --- - Objects are the basic run-time entities in an object-oriented system. - They are variables o...

Open this answer on its own page →

2076 · 5 marks

How object oriented programming differs from object based programming language? Discuss benefits of OOP. [5]

--- Object-Based Programming languages support objects and encapsulation but do not support inheritance and polymorphism. They are limited to using objects as data structures without the full power of OOP. Object-Oriented Programming languages support all four pillars: Encapsulation, Abstraction,...

Open this answer on its own page →

Overview of structured programming approach

2078 · 5 marks

What is structured programming? Discuss characteristics and problems associated with structured programming. [5]

Structured programming (also called Procedure Oriented Programming) is a programming paradigm that contains well-structured steps and procedures, using different functions for different tasks in a program. It follows a top-to-bottom (top-down) approach to solve problems systematically, where func...

Open this answer on its own page →

Object oriented programming approach

2080.1 · 5 marks

Define object. What are the benefits of Object Oriented Programming Language? [5]

Show solved answer

Object and Benefits of Object Oriented Programming Language


Definition of Object

An object is a basic run-time entity in an object-oriented system. Objects are variables (instances) of a user-defined data type called a class. They contain both data and code to manipulate that data.

"Objects are the basic run-time entities in an object-oriented system... In fact, objects are variables of the type class."

Key characteristics of an object:

  • Objects take up space in memory and have an associated address (like structures or unions in C).
  • When a program is executed, objects interact by sending messages to one another.
  • Program objects are chosen such that they match closely with real-world objects.

Example:

class person {
    char name[20];
    int age;
public:
    void getdetails() { }
};

int main() {
    person p1;   // p1 is an object of class person
}

Here, p1 is an object of class person that holds its own copy of name and age.


Benefits of Object Oriented Programming (OOP)

FeatureBenefit
Data Hiding / SecurityOOP provides access specifiers (private, public, protected) to restrict access to data, making programs more secure. Procedural languages lack this.
Modularity (Objects)Programs are divided into small, manageable units called objects, making code easier to understand and maintain.
Easy to Add New Data and FunctionsAdding new data members and member functions to a class is easy without disturbing the rest of the program. In procedural programming, adding new data requires revising all functions that access it.
OverloadingOOP supports function and operator overloading, allowing the same name to be used for different purposes, which is not possible in procedural-oriented programming.
Real-World ModelingOOP is based on real-world entities, making it easier to model and solve real-world problems. Procedural programming is action-oriented and does not model real-world problems well.
Bottom-Up ApproachOOP follows a bottom-up approach, which is more systematic for designing large and complex programs.
Reusability (Inheritance)Classes can be reused and extended through inheritance, reducing redundancy and saving development time.

Summary

In short, OOP overcomes the major drawbacks of procedural programming by providing security through data hiding, real-world modeling, easy extensibility, and code reusability, making it the preferred approach for developing large-scale, maintainable software systems.

Open this answer on its own page →