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?
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?