I
Immortal Nephi
We discussed proxy class with getters / setters in earlier posts.
You said design is flawed if getters / setters are defined in public.
In another words, my answer is no and design is not flawed. You
should judge yourself and be aware that your responsibility is to
assure test to be successful.
My writing is not clear. I apologize. I get information from the
book. Please read page 97 of Deitel How to program C++ 6/e if you
have a copy of book. It does explain in full details the introduction
to class in chapter 3.
My question remains unanswered. You can declare and define 100
member functions in private. You should always put getters / setters
in each member function out of 100 member functions. What happen if
you change data member’s variable name? You have to change it to all
100 member functions. Modification wastes your time.
You should not use data members directly from 100 member functions.
You always access data members indirectly through getters / setters’
member function.
Let me give you an example like you described engine in earlier
posts. Think of black chip. Black chip is like CPU. You define
getReadWrite(), getAddressBus(), getDataBus(), setDataBus(), and run()
in public on interface.
The client needs to use all member functions in interface. run() is
executed before you get information from getAddressBus(). Then,
AddressBus is connected to RAM to retrieve data. If getReadWrite() is
set to read only, you use setDataBus(), otherwise if getReadWrite() is
set to write only, you use getDataBus().
run() does the rest to work with 100 member functions. You are going
to agree that CPU class is a good design. What if you want to add
debug() to the interface? You define displayAllRegisters().
DisplayAllRegisters() read internal data members directly and display
the information like accumulator register and program counter
register. Again, the design is very good.
You are tempted to add setAccumulator() or setProgramCounter() on the
interface. Then, my answer is yes and design is flawed because you
don’t want the clients to know internal registers like direct data
members. You put CPU class to one of these ancient computer
emulator. The software running in emulation will crash if client
modifies internal registers directly through setAccumulator() or
setProgramCounter().
All other implantations in source code are hidden. Only interface is
provided in proxy class. Do my explanation make sense?
Can you please state your opinion for the best C++ practice? Should
you write direct data members to all 100 member functions before you
test all of them to be 100% successful? Or…should you write indirect
data members through getters / setters to all 100 member functions and
they are defined in private?
You said design is flawed if getters / setters are defined in public.
In another words, my answer is no and design is not flawed. You
should judge yourself and be aware that your responsibility is to
assure test to be successful.
My writing is not clear. I apologize. I get information from the
book. Please read page 97 of Deitel How to program C++ 6/e if you
have a copy of book. It does explain in full details the introduction
to class in chapter 3.
My question remains unanswered. You can declare and define 100
member functions in private. You should always put getters / setters
in each member function out of 100 member functions. What happen if
you change data member’s variable name? You have to change it to all
100 member functions. Modification wastes your time.
You should not use data members directly from 100 member functions.
You always access data members indirectly through getters / setters’
member function.
Let me give you an example like you described engine in earlier
posts. Think of black chip. Black chip is like CPU. You define
getReadWrite(), getAddressBus(), getDataBus(), setDataBus(), and run()
in public on interface.
The client needs to use all member functions in interface. run() is
executed before you get information from getAddressBus(). Then,
AddressBus is connected to RAM to retrieve data. If getReadWrite() is
set to read only, you use setDataBus(), otherwise if getReadWrite() is
set to write only, you use getDataBus().
run() does the rest to work with 100 member functions. You are going
to agree that CPU class is a good design. What if you want to add
debug() to the interface? You define displayAllRegisters().
DisplayAllRegisters() read internal data members directly and display
the information like accumulator register and program counter
register. Again, the design is very good.
You are tempted to add setAccumulator() or setProgramCounter() on the
interface. Then, my answer is yes and design is flawed because you
don’t want the clients to know internal registers like direct data
members. You put CPU class to one of these ancient computer
emulator. The software running in emulation will crash if client
modifies internal registers directly through setAccumulator() or
setProgramCounter().
All other implantations in source code are hidden. Only interface is
provided in proxy class. Do my explanation make sense?
Can you please state your opinion for the best C++ practice? Should
you write direct data members to all 100 member functions before you
test all of them to be 100% successful? Or…should you write indirect
data members through getters / setters to all 100 member functions and
they are defined in private?