Define Object

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
}
 
C

Christopher Pisz

Bryan Parkoff said:
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.

Says who? What class? All classes? Are you trying to dictate what a class is
or what your planned implementation is?
However, functions are always shared with one or more objects,

What do you mean shared? How is it "shared"?
but each object has its own separate variables.

I'd hope so.
It allows to reduce unreadable messy source code and bugs.

What is "it?"
However, I do not want to use a pointer to bind variables and functions
inside class, otherwise, it can degrade performance.

What do you mean "bind"? How is performance degraded? And what class are you
talking about?
Procedural Oriental Programming is only the solution.

Solution to what?
This allows global variables and global functions to be placed inside
namespace on one module like one header inside.

What is "this"?
If I want to define more than one object, I can create an array of each
global variables.

Sure... a variable is an object after all.
The global functions can always be shared with array of variables.

What do you mean shared? shared with whom and how? What does an array have
to do with it?
After all global variables and global functions are defined inside
namespace on one module, the module can become a header file.

No matter what you are talking about, this is _probably_ a bad idea. But, I
don't know what you are talking about.
Few functions use extern keyword so it can be used to all module of C++
source code.

What? What is "it"? "used to all module"? huh?
All global functions and global variables do not have extern keyword so
they will be inaccessible to all moudle of C++ source code.

Are you trying to say that functions and variables that are not declared to
be extern are not visible outside your module?
Please convince me if you think is best to advise.

I think it is best you seek advise rather than advise.
Should I use Procedural Oriental Programming or Object Oriental
Programming.

I dunno. You haven't said what you are trying to accomplish.
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.

I don't know what having one module has to do with anything else in that
paragraph.
They will not be able to see inaccessible global variables and global
functions. It helps to keep source code clean.

Not exposing some variables and functions outside your .dll keeps source
code clean? I'd better tell some of my messy co-workers.
Please let me know what you think and try to suggest what I should design
object using POP or OOP.

I think I have no idea what you are asking. I suggest you design a program,
but you already objected.

Here is an example.

Of what?
<snip>

I'd love to help, but I cannot begin to decypher the incomplete sentences
you posted. Even if english is your second language, the post doesn't make
enough sense for me to determine what the question is. Do you want to know
why something you are designing would be better done OOP vs Procedural? What
are you trying to accomplish? What is your .dll supposed to do?
 
D

Dave Rahardja

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 read your post correctly, you are trying to eliminate the overhead
associated with the this pointer used in every non-static member
function call; and you are trying to do this by creating a "one module,
one object" pattern, substituting module-static variables for member
variables. Is this correct?

This pattern is available in C++, in exactly the way you did it. If
your object is a singleton, then this is a viable alternative API to
your algorithm.

Your very next paragraph, however, highlights the weakness of this
approach: Having multiple instances of the class puts the overhead
right back. Additionally, using arrays to hold instances of each member
variable, offset by some index, introduces problems of its own. For one
thing, how do you keep track of what index each object has? Is storing
this information any cheaper than maintaining an object pointer?

-dr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top