我理解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設計的好開始嗎?有人有建議或改進嗎?