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.
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]
2076 · 5 marks
How object oriented programming differs from object based programming language? Discuss benefits of OOP. [5]
Overview of structured programming approach
2078 · 5 marks
What is structured programming? Discuss characteristics and problems associated with structured programming. [5]
Object oriented programming approach
2080.1 · 5 marks
Define object. What are the benefits of Object Oriented Programming Language? [5]
Show solved answerHide 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)
| Feature | Benefit |
|---|---|
| Data Hiding / Security | OOP 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 Functions | Adding 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. |
| Overloading | OOP 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 Modeling | OOP 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 Approach | OOP 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.
Make Unit 1 stick
Practice CSC166 with flashcards & quizzes