Skip to main content
added 1 character in body
Source Link
Ewan
  • 84.6k
  • 5
  • 91
  • 189

Separate the Object in code from its persistence format.

Imagine I add a requirement where I want to load binary files and save them as xml files.

Hexagons v = binaryFileReader.Load(filename);
v.AddHex(1,2);
xmlFileWriter.Save(v);

the Hexagon class is only concerned about the visualization. It only has methods related to setting the colours, adding new elements etc etc

The binaryFileReader/Writer class only knows about converting in memory Hexagon objects to the binary format file and back again. Similarly the xmlFileWriter just knows about xml and Hexagons.

Now if I addaadd a new Visualization type i have options. I can improve the file readers, adding in some knowledge about multiple visualisations, Or I can create a brand new class that deals with the new visualisation type.

Similarly, if I add a new file type, I havecan create a new CsvFileReaderWriter object to deal with that.

Separate the Object in code from its persistence format.

Imagine I add a requirement where I want to load binary files and save them as xml files.

Hexagons v = binaryFileReader.Load(filename);
v.AddHex(1,2);
xmlFileWriter.Save(v);

the Hexagon class is only concerned about the visualization. It only has methods related to setting the colours, adding new elements etc etc

The binaryFileReader/Writer class only knows about converting in memory Hexagon objects to the binary format file and back again. Similarly the xmlFileWriter just knows about xml and Hexagons.

Now if I adda new Visualization type i have options. I can improve the file readers, adding in some knowledge about multiple visualisations, Or I can create a brand new class that deals with the new visualisation type.

Similarly, if I add a new file type, I have create a new CsvFileReaderWriter object to deal with that.

Separate the Object in code from its persistence format.

Imagine I add a requirement where I want to load binary files and save them as xml files.

Hexagons v = binaryFileReader.Load(filename);
v.AddHex(1,2);
xmlFileWriter.Save(v);

the Hexagon class is only concerned about the visualization. It only has methods related to setting the colours, adding new elements etc etc

The binaryFileReader/Writer class only knows about converting in memory Hexagon objects to the binary format file and back again. Similarly the xmlFileWriter just knows about xml and Hexagons.

Now if I add a new Visualization type i have options. I can improve the file readers, adding in some knowledge about multiple visualisations, Or I can create a brand new class that deals with the new visualisation type.

Similarly, if I add a new file type, I can create a new CsvFileReaderWriter object to deal with that.

Source Link
Ewan
  • 84.6k
  • 5
  • 91
  • 189

Separate the Object in code from its persistence format.

Imagine I add a requirement where I want to load binary files and save them as xml files.

Hexagons v = binaryFileReader.Load(filename);
v.AddHex(1,2);
xmlFileWriter.Save(v);

the Hexagon class is only concerned about the visualization. It only has methods related to setting the colours, adding new elements etc etc

The binaryFileReader/Writer class only knows about converting in memory Hexagon objects to the binary format file and back again. Similarly the xmlFileWriter just knows about xml and Hexagons.

Now if I adda new Visualization type i have options. I can improve the file readers, adding in some knowledge about multiple visualisations, Or I can create a brand new class that deals with the new visualisation type.

Similarly, if I add a new file type, I have create a new CsvFileReaderWriter object to deal with that.