Confused One Object and Two or more Objects

I

Immortal Nephi

There are repeated discussions in newsgroups and websites about
namespace and singleton. The programmers who struggle to make their
decision to choose either namespace or singleton. They always think
“One Object” and “Two or more Objects”.
One object is like a disk drive. The programmers choose to use
namespace, but they are unable to use encapsulation if they don’t use
class. They place global variables and global functions in the
namespace. They are visible to all multiple source codes.
The programmers decide to use this method because they want critical
performance for one object as disk drive. Global variables increase
performance because they can be accessed directly by any function and
the overhead of passing data to functions is eliminated. It is
explained in the page 1292 of Deitel How to program C++ 6th edition
book.
Why do they choose namespace if they design to have only one file
scope? Why not they do not use class? They should use singleton.
All member variables and member functions are declared static inside
singleton class while they are treated like true global variables and
global functions.
The programmers choose to create same two or more objects. Two or
more objects is like a car. They should use car class with member
variables and member functions because car class has its own one copy
for each object with good encapsulation.
They can put them on the screen. The car objects are moving around
the screen like game programming. They don’t need critical
performance, but memory cache may be good.
Why do they claim that namespace is perfect for critical
performance? Why not they claim singleton with or without static for
good memory cache?
 
F

Francesco S. Carta

There are repeated discussions in newsgroups and websites about
namespace and singleton. The programmers who struggle to make their
decision to choose either namespace or singleton. They always think
“One Object” and “Two or more Objects”.
One object is like a disk drive. The programmers choose to use
namespace, but they are unable to use encapsulation if they don’t use
class. They place global variables and global functions in the
namespace. They are visible to all multiple source codes.
The programmers decide to use this method because they want critical
performance for one object as disk drive. Global variables increase
performance because they can be accessed directly by any function and
the overhead of passing data to functions is eliminated. It is
explained in the page 1292 of Deitel How to program C++ 6th edition
book.
Why do they choose namespace if they design to have only one file
scope? Why not they do not use class? They should use singleton.
All member variables and member functions are declared static inside
singleton class while they are treated like true global variables and
global functions.
The programmers choose to create same two or more objects. Two or
more objects is like a car. They should use car class with member
variables and member functions because car class has its own one copy
for each object with good encapsulation.
They can put them on the screen. The car objects are moving around
the screen like game programming. They don’t need critical
performance, but memory cache may be good.
Why do they claim that namespace is perfect for critical
performance? Why not they claim singleton with or without static for
good memory cache?

Who is "they"? Apart of that, I'm not sure I have exactly understood
your position.

My position is that as long as the language blesses and the compiler
baptizes, if I find it the best solution, well it makes it in. Were it
a namespace, a singleton or a GOTO too, I wouldn't worry that much
about "their" opinions. I happen to care a lot about individuals('),
though.

Just my two cents, w.r.t. the adj. in my b.n. sig.

Cheers,
Francesco
____________________________
Francesco S. Carta, hobbyist
http://fscode.altervista.org
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top