Class & Objects
对象,不存在的

Procedural and Object-Oriented Programmming
Procedural programming focuses on the process/actions that occur in a program
Object-Oriented programming is based on the data and the functions that operate on it. Objects are instances of new data types that represent the data and the operations on that data.
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
Limitations of Procedural Programming
If the data structures change, many functions must also be changed
Programs that are based on complex function hierarchies are:
difficult to understand and maintain
difficult to modify and extend
easy to break
Object-Oriented Programming Terminology
Class: like a struct (allows bundling of related variables), but variables and functions in the class can have different properties than in a struct
Object: an instance of a class, in the same way that a variable can be an instance of a struct
Object-Oriented
Model real world objects(mostly)
Bunding
Related data (Attributes)
in C++ called data members
Related methods (Actions)
in C++ callled 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
Visibility

data hiding: restricting access to certain members of an object
public interface: members of an object that are available outside of the object. This allows the object to provide access to some data and functions without sharing its internal details and design, and provides some protection from data corruption

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
Last updated
Was this helpful?