我理解OO编程的工作原理,但实际使用多于一个或两个类的实际经验很少。当涉及到实际使用它时,我与OO Design部分斗争。我来到以下可能受益于OO的情况:OO设计数据以映射
我有几组来自不同来源的数据,一些来自文件,另一些来自互联网通过API和其他甚至不同来源的数据。当涉及到它们包含的数据时,它们中的一些非常相似,其中一些实际上是不同的。我想要将这些数据可视化,并且由于几乎所有的数据都是基于我在地图上使用某种位置的标记(使用Folium in python创建基于Leaflet的地图)的位置(有一点点弹出信息)。在某些情况下,我还希望创建一个包含数据概述的pdf并将其保存到磁盘。
我想出了主意类以下(一开始)(用Python编写的,以显示想法):
class locationData(object):
# for all the location based data, will implement coordinates and a name
# for example
class fileData(locationData):
# for the data that is loaded from disk
class measurementData(fileData):
# measurements loaded from disk
class modelData(fileData):
# model results loaded from disk
class VehicleData(locationData):
# vehicle data loaded from a database
class terrainData(locationData):
# Some information about for example a mountain
class dataToPdf(object):
# for writing data to pdf's
class dataFactory(object):
# for creating the objects
class fileDataReader(object):
# for loading the data that is on disk
class vehicleDatabaseReader(object):
# to read the vehicle data from the DB
class terrainDataReader(object):
# reads terrain data
class Data2HTML(object):
# puts the data in Folium objects.
的数据考虑到输出我想,每一个数据类在它自己的数据(因为它知道它有什么信息),例如render()方法。渲染方法(可能是字典)的输出将用于data2pdf或data2html,尽管我并不确定如何执行此操作。
这是OO设计的好开始吗?有人有建议或改进吗?