Docsity

Object-Oriented Programming (OOP) Complete Exam Prep & Lecture Notes, Summaries of Object Oriented Programming

Toggle sidebar
bg1
Object-Oriented Programming (OOP)
Complete Exam Prep Notes
1. Procedural vs. Object-Oriented Programming
Procedural Programming: Focuses on functions and sequences of
commands (e.g., C). Data and functions are separate, making large
codebases harder to maintain.
Object-Oriented Programming (OOP): Focuses on objects that
combine both data (attributes) and behavior (methods). It mimics
real-world entities, making code modular and reusable.
2. Core Building Blocks
Class: A user-defined data type that acts as a blueprint, template,
or contract for creating objects. It takes up no memory space until
instantiated.
Object: A basic runtime entity and an instance of a class. It
occupies space in memory.
Constructor: A special member function initialized automatically
during object creation.
o
Default Constructor:
Takes no arguments.
o
Parameterized Constructor:
Takes arguments to initialize fields
with custom values.
o
Copy Constructor:
Creates a new object by copying an existing
object.
3. The 4 Pillars of OOP (With Implementation Logic)
A. Encapsulation
The wrapping up of data and member functions into a single unit (Class).
It enforces Data Hiding by keeping variables private and exposing them
only through public methods.
Java
// Example in Java
class Student {
pf3

Partial preview of the text

Download Object-Oriented Programming (OOP) Complete Exam Prep & Lecture Notes and more Summaries Object Oriented Programming in PDF only on Docsity!

Object-Oriented Programming (OOP)

Complete Exam Prep Notes

1. Procedural vs. Object-Oriented ProgrammingProcedural Programming: Focuses on functions and sequences of commands (e.g., C). Data and functions are separate, making large codebases harder to maintain.  Object-Oriented Programming (OOP): Focuses on objects that combine both data (attributes) and behavior (methods). It mimics real-world entities, making code modular and reusable. 2. Core Building BlocksClass: A user-defined data type that acts as a blueprint, template, or contract for creating objects. It takes up no memory space until instantiated.  Object: A basic runtime entity and an instance of a class. It occupies space in memory.  Constructor: A special member function initialized automatically during object creation.

o Default Constructor: Takes no arguments.

o Parameterized Constructor: Takes arguments to initialize fields

with custom values.

o Copy Constructor: Creates a new object by copying an existing

object.

3. The 4 Pillars of OOP (With Implementation Logic) A. Encapsulation The wrapping up of data and member functions into a single unit (Class). It enforces Data Hiding by keeping variables private and exposing them only through public methods. Java // Example in Java class Student {

private String name; // Private variable hidden from direct access // Public Getter public String getName() { return name; } // Public Setter public void setName(String newName) { this.name = newName; } } B. Abstraction Hiding complex implementation details and showing only the essential features to the user. Achieved using Abstract Classes (which can have abstract and concrete methods) or Interfaces (which define pure behaviors). C. Inheritance The process by which one class inherits the attributes and methods of another.  Types: Single, Multilevel, Hierarchical, Multiple (supported via interfaces in Java/C#), and Hybrid. C++ // Example in C++ class Animal { public: void eat() { cout << "Eating..."; } }; class Dog : public Animal { // Dog inherits from Animal public: void bark() { cout << "Barking..."; } }; D. Polymorphism The ability of a single function or execution to manifest in multiple forms.