Presentation is loading. Please wait.

Presentation is loading. Please wait.

Classes & Objects CSCE 121 J. Michael Moore.

Similar presentations


Presentation on theme: "Classes & Objects CSCE 121 J. Michael Moore."— Presentation transcript:

1 Classes & Objects CSCE 121 J. Michael Moore

2 Datatypes Simple Compound int, double, bool, etc. Homogeneous Heterogeneous Array Vector struct Class

3 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.

4 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.

5 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

6 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

7 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)

8 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


Download ppt "Classes & Objects CSCE 121 J. Michael Moore."

Similar presentations


Ads by Google