Re: How to encapsulating Object?
On Sep 8, 5:48 pm, Noah Roberts <u...@example.net> wrote:
Immortal_Ne...@hotmail.com wrote:
Sometimes, programmers decide to create only one object. One object
is used for a whole program. You can run two or more programs at the
same time. Each program has a copy of its own object.
They decide to use global variable and global function. The
namespace is the only way to encapsulate global variable and global
function. The source code is much easier to be readable if namespace
is used. Multiple modules can share global varable and global
function without any confusion.
They can create dynamic linked library to include global variable an=
d
global functions. The clients can reuse library.
If programmers decde to create more than one object on a whole
program, class is the answer.
Take a look at my example code. Please let me know if my source cod=
e
looks good design. If only one object is ued, should I use global
variables and globa functions or struct with global function?
singleton
Maybe. His first sentence is "Sometimes, programmers decide to
create only one object"; if the client programmer decides to
create only one object, then he only creates one object, and
that's it. A singleton is used if the abstraction of the class
is such that it doesn't make sense to create more than one
object (and that object should have the lifetime of the
program).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34