在構建集成引擎時,我一直在尋找有關設計模式的一些提示。處理導入和導出(集成)的.NET服務
我有一個SQL Server,它包含我想要導出的所有數據(這也是我插入導入數據的位置)。我有一個服務可以根據時間間隔執行命令等等。儘管我真正努力的一件事情就是處理軟件中數據處理的方式。
例如,在一個出口項目我做我有類似的這種
// Entity order
public class Order {
int OrderID { get; set; }
string OrderNo { get; set; }
// One order can include loads of registrations
// A registration can only have a reference to one order
// Basically a mirror of the database
List<Registration> RegistrationList { get; set; }
}
// Entity registration
public class Registration {
int RegistrationID { get; set; }
string Name { get; set; }
// Some more variables
}
// Controller(?)
public class OrderController : IControlOrder
{
private IControlRegistrations _registrationController;
public OrderController()
{
this._registrationController = new RegistrationController();
}
public List<Order> get() {
List<Order> orderList = new List<Order>();
// Query database
foreach(...) {
// Short example
Order order = new Order();
order.OrderNo = ...
order.OrderID = ...
order.RegistrationList = _registrationController.getRegistrationsBasedOnOrder(order);
}
// Iterate through every row
// Create a new Order-object per iterate
return orderList;
}
public void updateOrder(Order order) {
// Update the order in the database (set exported-flag)
}
}
public RegistrationController : IControlRegistrations
{
public List<Registration> getRegistrationsBasedOnOrder(Order order)
{
List<Registration> list = new List<Registration>();
// Query DB based on OrderID
return list;
}
public void update(Registration registration)
{
// Update the registration in the database
}
}
// Output
public class Output
{
private IControlOrder _controller;
public Output(IControlOrder controller)
{
this._controller = controller;
}
public void export()
{
// Build XML
// ... Example
//
//<Orders>
// <Order>
// <OrderNo>KF322</OrderNo>
// <RegistrationList>
// <!-- All the registrations with a reference to this order -->
// </RegistrationList>
// </Order>
// <Order>
// <OrderNo>KF323</OrderNo>
// <RegistrationList>
// <!-- All the registrations with a reference to this order -->
// </RegistrationList>
// </Order>
//</Orders>
foreach(Order order in _controller.get())
{
// Create the order info in the XML, then create registrations
foreach(Registration reg in order.RegistrationList)
{
// Create the registration list in the XML
}
}
// Save the file to a network drive.
}
}
我敢肯定,我違反了設計模式的每一個規則有一個結構。最終,我的代碼變得混亂,每層的責任(不知道我是否可以稱之爲圖層)變得混亂起來。例如,如果一個訂單也與描述和地址有一對多的關係,那麼類會變得難以置信地混亂。在我的下一個項目中,我也將執行導入,並且我不會僅導出訂單,而且還會導出其他主數據。所以我相信我必須在接口,幫助類等方面很聰明。在輸出文件或將其插入數據庫之前,我還必須驗證從數據庫和集成程序中檢索的所有數據。
你們有沒有人知道集成引擎的良好設計模式(只是一個理論)?這個問題可能並不具有建設性,但是當我們使用的小房子設計會比數十倍大的時候還不夠。
任何幫助非常感謝:)謝謝!
這是很酷多少早點有意義的,因爲你只需要改變的「小細節」像術語。 EF讓我感到困惑,因爲它就像一個魔術盒給我,可能是因爲我自己沒用過,只是看到了一些使用它的產品代碼。我想到的另一件事是驗證我插入到模型中的模型數據。但是我相信我會在某些時候解決這個問題:)這個設計模型是否指定了具體的東西?感謝您的幫助,只是術語的變化使其可以理解! – Alex07
我很抱歉再次打擾您,我決定按照您提出的命名約定來採用這種模式。如果我以上述爲例,我想創建兩個輸出,前面提到的XML和一個Web服務連接,以及一個報告(我真正輸出了什麼)。 IOutputService應該是一個具有定義的報告方法和抽象的Export-method的抽象類?你爲這個特定目的建議了什麼設計? :) – Alex07
@ Alex07:聽起來像一個很好的,自包含的代碼審查問題http://codereview.stackexchange.com –