Classes & Objects CSCE 121 J. Michael Moore
Datatypes Simple Compound int, double, bool, etc. Homogeneous Heterogeneous Array Vector struct Class
Procedural Programming So far the focus is on the steps, actions, and functions. Data is subordinate to functions. Object Oriented Programming Focus is on the data. Functions are subordinate to the data.
Object Oriented Model real world objects (mostly) Grouping Related data (Attributes) In C++ called data members Related actions (Methods) In C++ called member functions Communication occurs through messages Object is spoken to by calling a method on it.
Concept of Class Class is a generic description Think blueprint Object is an instance of the class Think the blue house on the corner And the red one on the next block And the green one next door I.e. there are multiple instances of a single class
Information Hiding / Encapsulation Visibility Creating for others to use (e.g. make a Library) Information Hiding / Encapsulation Public Want some things visible to others What Tend to be methods / member functions Private Want some things hidden from others. How Might Change Tend to be data members / attributes
Interface Public Attributes Methods Private Methods Attributes Call with parameters Private Helper Functions Rare Get / Set values and enforce rules. Accessor & Mutator methods (getters/setters) Constructor (initializes object)
C++ Note Struct and class are almost interchangeable in C++ Struct was used in C for heterogeneous data Class adopted into C++ (label was common in other languages) Class concept groups not only heterogeneous data, but the methods that act on them. This capability was given to structs as well. Differ in default visibility Class is private by default Struct is public by default