S
SpOiLeR
Hi everybody.
My problem is this. I have 4 different text file formats which basically
contain same data differently formated. I have class ParsedData which
handles data from this files. I also have 4 parses which can read from
files into ParsedData. Parsers should never be called explicitly (they
should only be called from ParsedData ctor). What is the best way to
protect those parsers? This is what I came up to so far:
1.
Most obvious way is to put all parser methods into private part of the
ParsedData. But... Each parser has its own helper methods (roughly cca. 20
per parser) which are in no way related to ParsedData class and don't touch
any of the ParsedData data members. It doesn't seem logical to put them
into ParsedData interface. Where to put their declarations? I was thinking
of putting their declarations directly into source file of each given
parser so they remain hidden from class interface making interface a *lot*
more tidy and readable. How good is this from the point of code
maintability? Is it a good coding practice? I must mention that I don't
care if user sees this methods exposed, I just want to make ParsedData
interface clearer.
2.
As each parser is a "class" of methods on their own I thought encapsulating
each one into it's own class and pronounce those classes friends to
ParsedData. But this way, they are not protected any more and can be called
independently of ParsedData objects which is exactly the thing I want to
avoid.
I am doing all this because I started learning language a month ago and
wanted to do some coding to get used to basic syntax and std library
features learnt so far. So please bear in mind that I'm quite a newbie in
C++ (with a few years of experience in C programming). TIA
My problem is this. I have 4 different text file formats which basically
contain same data differently formated. I have class ParsedData which
handles data from this files. I also have 4 parses which can read from
files into ParsedData. Parsers should never be called explicitly (they
should only be called from ParsedData ctor). What is the best way to
protect those parsers? This is what I came up to so far:
1.
Most obvious way is to put all parser methods into private part of the
ParsedData. But... Each parser has its own helper methods (roughly cca. 20
per parser) which are in no way related to ParsedData class and don't touch
any of the ParsedData data members. It doesn't seem logical to put them
into ParsedData interface. Where to put their declarations? I was thinking
of putting their declarations directly into source file of each given
parser so they remain hidden from class interface making interface a *lot*
more tidy and readable. How good is this from the point of code
maintability? Is it a good coding practice? I must mention that I don't
care if user sees this methods exposed, I just want to make ParsedData
interface clearer.
2.
As each parser is a "class" of methods on their own I thought encapsulating
each one into it's own class and pronounce those classes friends to
ParsedData. But this way, they are not protected any more and can be called
independently of ParsedData objects which is exactly the thing I want to
avoid.
I am doing all this because I started learning language a month ago and
wanted to do some coding to get used to basic syntax and std library
features learnt so far. So please bear in mind that I'm quite a newbie in
C++ (with a few years of experience in C programming). TIA