Easy tutorial for C / C ++ - class 1 (Object oriented programming and class)
Object
Oriented Programming (OOP) :
- Old programming is a function-oriented sequential
programming method by calling functions in the main function. This is called
procedural programming.
- Object-oriented programming is a programming in a way
that the program is made up of objects rather than a certain order. Objects can
have multiple member variables similar to struct. You can also define member
functions (methods) to perform the functions required by the object.
- Features of OOP include data abstraction,
encapsulation, data hiding, polymorphism, and inheritance.
Data abstraction : Simplifying the program by hiding
unnecessary information and showing only important information.
Encapsulation : A class uses multiple member variables and member functions
(methods) in a single unit. That is, you can encapsulate them into one
aggregate.
Data Hiding : Indicates that member variables are
indirectly accessed through member functions. (are not directly accessible)
Polymorphism : A single element (function or operators)
that allows for multiple concepts and behavior (number of data types and
arguments). (ex: operator overloading)
Inheritance: Features and functions of a specific object (functions of an
already defined class) can be inherited by other objects. This eliminates the
need to make redundant content unnecessary.
class
:
- It is a class that allows you to abstract data to
create new user-defined types. It is similar to a struct in that it has several
member variables, but a class can implement member functions (methods) to
perform more functions.
- The basic structure of a class is as follows: Class declaration and member
function definition.
class 'class name' {
"Access specifier":
'Data type' 'member variable';
...
"Access specifier":
'Data type' 'member function';
};
'Data type' 'member variable';
...
"Access specifier":
'Data type' 'member function';
};
'Data type' 'class name' :: 'member function ()
{...}
{...}
- First, specify 'class' and write the corresponding
'class name'. And declare member variables and member functions to be used.
Here, 'access specifier' (private, public, and protected) is a specifier
related to access rights and inheritance.
- When defining a member function, 'class name' is
created after 'data type' to be returned, and the scope operator (: :) is used
to indicate that the function belongs to the class. Then write the name of the
member function and write the contents of the function.
No comments:
Post a Comment