1
我有一個RavenDB文件你會如何構建這個RavenDB文檔的模型?
{
"RpcTechDataCollectionModel": {
"Weekend": "March 16 - 17, 2013",
"ServiceTitle": "Some Title",
"Notes": "",
"WeekendServices": [{
"ServiceTime": "",
"SiteName": "Bowridge",
"SoundOperator": "Rob",
"WorshipLeader": "Daryl",
"Notes": "",
"Songs": [{
"SongName": "Foo",
"MinSpl": "86",
"MaxSpl": "92",
"Note": ""
}, {
"SongName": "Bar",
"MinSpl": "89",
"MaxSpl": "96",
"Note": ""
}]
}, {
"ServiceTime": "",
"SiteName": "Bearspaw",
"SoundOperator": "Peter",
"WorshipLeader": "Tim",
"Notes": "",
"Songs": [{
"SongName": "Das",
"MinSpl": "86",
"MaxSpl": "91",
"Note": ""
}, {
"SongName": "Bar",
"MinSpl": "87",
"MaxSpl": "99",
"Note": ""
}]
}]
}
}
現在我想建立這樣的模型下面的結構,但我想知道什麼是最好的方法來組織的那樣。請注意,沒有一個子對象WeekendService
或Song
將父對象外使用的RpcTechCollectionModel
選擇一個將
namespace MyProject.Models {
using System.Collections.Generic;
public class RpcTechDataCollectionModel{
RpcTechDataCollectionModel(){
this.WeekendServices = new List<WeekendService>();
}
public string Weekend { get; set; }
public string ServiceTitle { get; set; }
public string Notes { get; set; }
public List<WeekendService> WeekendServices { get; set; }
public class WeekendService{
WeekendService(){
this.SongRecords = new List<SongRecord>();
}
public DateTime ServiceTime { get; set; }
public string SiteName { get; set; }
public string SoundOperator { get; set; }
public string WorshipLeader { get; set; }
public string Notes { get; set; }
public List<Song> Songs { get; set; }
public class Song {
public string SongName { get; set; }
public double MinSpl { get; set; }
public double MaxMax { get; set; }
public string Note { get; set; }
}
}
}
}
我喜歡這個,因爲它是非常乾淨的,而且容易理解。問題是,它在技術上違反了 「One class per file」 規則
方案二
public class RpcTechDataCollectionModel{
RpcTechDataCollectionModel(){
this.WeekendServices = new List<WeekendService>();
}
public string Weekend { get; set; }
public string ServiceTitle { get; set; }
public string Notes { get; set; }
public List<WeekendService> WeekendServices { get; set; }
}
public class WeekendService{
WeekendService(){
this.SongRecords = new List<SongRecord>();
}
public DateTime ServiceTime { get; set; }
public string SiteName { get; set; }
public string SoundOperator { get; set; }
public string WorshipLeader { get; set; }
public string Notes { get; set; }
public List<Song> Songs { get; set; }
}
public class Song {
public string SongName { get; set; }
public double MinSpl { get; set; }
public double MaxMax { get; set; }
public string Note { get; set; }
}
這並不違反這條規則,但似乎有點像的痛苦。
做這種或那種方式的優點/缺點是什麼,並且是一種被認爲是「正確/首選」的方式,還是在這種情況下更「浮在你的船上」?
這很有道理。如果我們需要將信息與當前的實現分離開來,那麼我認爲將它們全部解耦都會增加靈活性。 – 2013-03-18 20:37:08