Luigi said:
Are you passing to the parser the collection where to add the objects,
instaed of the whole container (of both men and women)?
Could you explain it a little bit further your solution?
I forget to mention that to me (in my application) men and women are the
same, i mena, i never thought to create sublasses of person since the do
not differ at all. The only difference is to with collection inside
people the are added.
One of the flexible ways, if you want to divide people
in future more, to do like this:
declare parser's storage class interface
{
};
At this point no sence to make "people" as derived from "storage",
because "people" contains more than one "storage"
You will be forced to pass people to parser if only parser will access
to all man/woman/children together, but simultaneously will have any
preffered selected type of storage (man for example).
declare people class interface
{
storage& man();
storage& woman();
storage& other();
};
declare parser class interface
{
parser:
arse(file&,storage&);
};
Usage
do_parse(Tpeople *people, Tparser *parser)
{
parser->parse("man.txt",people->Man() );
parser->parse("woman.txt",people->Woman() );
parser->parse("children.txt",people->other() );
parser->parse("old.txt",people->other() );
}
Tpeople *people = new Tpeople;
do_parse(people, new Tlex_parser);
do_parse(people, new Tbison_parser);
Not enough information to apply desing patterns, but all looks like
simplest kind of design pattern "builder" with "storage" as "concrete
builder without derived" and "parser" as "concrete derived from
director".