Classes are defined and how instances of classes, that is, objects, are used. In
addition, structs and unions are introduced as examples of special classes.
The Class Concept
Classes are the language element in C++ most important to the
support object-oriented programming (OOP). A class defines the properties and
capacities of an object.
Data Abstraction
Humans use abstraction in order to
manage complex situations. Objects and processes are reduced to basics and
referred to in generic terms. Classes allow more direct use of the results of
this type of abstraction in software development.
The first step towards solving a problem is analysis. In object-oriented programming, analysis comprises
identifying and describing objects and recognizing their mutual relationships.
Object descriptions are the building blocks of classes.
In C++, a class is a user-defined type. It contains data members, which describe the properties of the class, and
member functions, or methods, which
describe the capacities of the objects. Classes are simply patterns used to
instantiate, or create, objects of the class type. In other words, an object is
a variable of a given class.
Data Encapsulation
When you define a class, you also specify the private
members, that is, the members that are not available for external access, and
the public members of that class. An application program accesses objects by
using the public methods of the class and thus activating its capacities.
Access to object data is rarely direct, that is, object data is
normally declared as private and then read or modified by methods with public
declarations to ensure correct access to the data.
One important aspect of this technique is the fact that
application programs need not be aware of the internal structure of the data. If
needed, the internal structure of the program data can even be modified.
Provided that the interfaces of the public methods remain unchanged, changes
like these will not affect the application program. This allows you to enhance
an application by programming an improved class version without changing a
single byte of the application.
An object is thus seen to encapsulate its private structure,
protecting itself from external influences and managing itself by its own
methods. This describes the concept of data encapsulation concisely.
0 Comments