OOP Session 2
Programming Paradigms
1- Linear/sequential: single block of code executed line by line. Good for small
programs.
2- Functional: program is decomposed into a group of functions. Maintenance is
very hard and can’t represent real world. Suitable for embedded systems.
3- Object-oriented programming: system is a group of objects [each object has data
- behaviors]. Suitable for real world systems.
C++
C + OOP but not pure OOP as it has backward compatibility with C
User-Defined Datatypes
1- Struct
2- Class
Struct (structure)
It is a value type stored directly on the stack.
Lightweight, small and simple objects that don’t require inheritance or complex
reference-type behavior.
Struct used to define datatype only while class can be used to define datatype or
be container for set of utilities (helper methods).
How we
be struct
determine datatype will
or class?
Based on the object if small size and simple it will be struct if complex and
heavyweight it will be class.
Class
It is reference type – the reference/address is stored in the stack while the actual object
instance is allocated on the heap.