c++ - Design of an xml reader -


i have class xmlreader reads xml , class point represents point. point can have various types, different types described enum inside class point.

class xmlreader {      void read()     {         string typereadfromxml;         vector<double> coordinates;         point* pt = newpoint(typereadfromxml, coordinates);          // or         //string typereadfromxml;         //pointtype type= xmlreader::conversion(typereadfromxml);         //vector<double> coordinates;         //point* pt = newpoint(type, coordinates);     } };  class point {      point(string type, vector<double> v)     {         _type = conversion(type);     }      point(pointtype type, vector<double> v)     {         _type = type;     }  private:     enum pointtype {         type1,         type2     };      pointtype conversion(string){}      pointtype _type;     vector<double> _coords; }; 

is ok conversion string custom type in point class or preferable conversion in read method of xmlreader class ?

the problem converting string pointtype in point class if
change keywords of xml format, have change point class ( ie conversion method). think ?

usually, best practice design modules , components in orthogonal way possible.

in case, means point class cleanly encapsulated , not aware of, or dependent on underlying xml format, can reused other purposes: different xml format, json, other sources. makes easier understand reading code, , easier maintain.

this way, three-level architecture: xml format > conversion > point class.

there exceptions rules, of course, , in general, if there other goals code reuse, readability , maintenance (such as, if performance critical), can justify reducing number of levels in architecture.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -