B
Bryan Parkoff
An object can be defined using a class. The class contains variables
and functions. It has a pointer to bind variables and functions. If I want
to create more than one object. The class can have two objects with a
separate pointer. However, functions are always shared with one or more
objects, but each object has its own separate variables. It allows to
reduce unreadable messy source code and bugs.
However, I do not want to use a pointer to bind variables and functions
inside class, otherwise, it can degrade performance. Procedural Oriental
Programming is only the solution. This allows global variables and global
functions to be placed inside namespace on one module like one header
inside.
If I want to define more than one object, I can create an array of each
global variables. The global functions can always be shared with array of
variables. After all global variables and global functions are defined
inside namespace on one module, the module can become a header file. Few
functions use extern keyword so it can be used to all module of C++ source
code. All global functions and global variables do not have extern keyword
so they will be inaccessible to all moudle of C++ source code.
Please convince me if you think is best to advise. Should I use
Procedural Oriental Programming or Object Oriental Programming. I plan to
put one module into DLL. This allows the programmers to use my DLL to
access resuable global functions when they want to create one or more
objects. They will not be able to see inaccessible global variables and
global functions. It helps to keep source code clean.
Please let me know what you think and try to suggest what I should
design object using POP or OOP.
Here is an example.
Module #1
// foo.h
#ifndef FOO_H
#define FOO_H
namespace foo
{
extern int Object_Count;
extern int Run(void); // accessible to all modules
} // foo
#endif
// foo.cpp
namespace foo
{
int Object_Count = 0;
int g_a[5] = 0; // global variables are private
int g_b[5] = 0;
int g_c[5] = 0;
// Three functions below are private.
void A(void)
{
g_a[Object_Count] += 1;
}
void B(void)
{
g_b[Object_Count] += 2;
}
void C(void)
{
g_c[Object_Count] += 4;
}
// Public
int Run(void)
{
if (Object_Count > 5)
return -1; // Exceed Object_Count limit and return failed.
A();
B();
C();
}
} // foo
Moudle #1
// Main.cpp
#include "foo.h"
int main(void)
{
foo::Object_Count = 0;
foo::Run();
foo::Object_Count = 1;
foo::Run();
foo::g_a = 5; // Error without extern keyword so it is private
foo::A(); // Error without extern keyword so it is private
}
and functions. It has a pointer to bind variables and functions. If I want
to create more than one object. The class can have two objects with a
separate pointer. However, functions are always shared with one or more
objects, but each object has its own separate variables. It allows to
reduce unreadable messy source code and bugs.
However, I do not want to use a pointer to bind variables and functions
inside class, otherwise, it can degrade performance. Procedural Oriental
Programming is only the solution. This allows global variables and global
functions to be placed inside namespace on one module like one header
inside.
If I want to define more than one object, I can create an array of each
global variables. The global functions can always be shared with array of
variables. After all global variables and global functions are defined
inside namespace on one module, the module can become a header file. Few
functions use extern keyword so it can be used to all module of C++ source
code. All global functions and global variables do not have extern keyword
so they will be inaccessible to all moudle of C++ source code.
Please convince me if you think is best to advise. Should I use
Procedural Oriental Programming or Object Oriental Programming. I plan to
put one module into DLL. This allows the programmers to use my DLL to
access resuable global functions when they want to create one or more
objects. They will not be able to see inaccessible global variables and
global functions. It helps to keep source code clean.
Please let me know what you think and try to suggest what I should
design object using POP or OOP.
Here is an example.
Module #1
// foo.h
#ifndef FOO_H
#define FOO_H
namespace foo
{
extern int Object_Count;
extern int Run(void); // accessible to all modules
} // foo
#endif
// foo.cpp
namespace foo
{
int Object_Count = 0;
int g_a[5] = 0; // global variables are private
int g_b[5] = 0;
int g_c[5] = 0;
// Three functions below are private.
void A(void)
{
g_a[Object_Count] += 1;
}
void B(void)
{
g_b[Object_Count] += 2;
}
void C(void)
{
g_c[Object_Count] += 4;
}
// Public
int Run(void)
{
if (Object_Count > 5)
return -1; // Exceed Object_Count limit and return failed.
A();
B();
C();
}
} // foo
Moudle #1
// Main.cpp
#include "foo.h"
int main(void)
{
foo::Object_Count = 0;
foo::Run();
foo::Object_Count = 1;
foo::Run();
foo::g_a = 5; // Error without extern keyword so it is private
foo::A(); // Error without extern keyword so it is private
}