除了 MVVM 以及 WPF 应用程序整体结构的 MVC 模式之外,您究竟如何将应用程序的模型/控制器方面分解为子组件?我问的原因是我从上述模式的角度构建解决方案没有问题,但是当涉及到实际编写后端时;我觉得我捏造了很多。从用户的角度来看,我最终得到了高质量的应用程序,但我的设计美学不允许我接受这一点。
澄清; 我的很多业务逻辑都无法以任何简单或有意义的方式重构为一个类(或类层次结构,以及所有关联的接口),而无需更改整个应用程序。我现在专业开发一年半了,可能是经验不足的问题;但我觉得这仍然不是借口。任何指向这个公认的开放式问题的指针?
编辑:代码请求(在 Silverlight 中)- 以下是来自拖放分配应用程序中 mousebuttonup 处理程序的-snippet-,该应用程序是更大应用程序的一部分-
我真的不喜欢逻辑是多么生硬,并且讨厌它完全无法分解的方式,因为一切都被塞进事件处理程序中。
//determine if there is a previously existing allocated sale corresponding to this purchase's ID
SaleWS allocSaleExisting = colltoaddsale.FirstOrDefault(s => (s.p_TRADEID == allocPurch.TRADEID));
if (allocSaleExisting != null && allocSale.TRADEID == allocSaleExisting.TRADEID)
{
PurchaseWS allocPurchExisting = colltoadd.First(p => p.TRADEID == allocPurch.TRADEID);
//allocPurchExisting.AMOUNT += allocPurch.AMOUNT;
allocSaleExisting.AMOUNT += allocSale.AMOUNT;
allocPurchExisting.AMOUNT += allocSale.AMOUNT;
allocPurch.AMOUNT -= allocSale.AMOUNT;
colltoaddsale.Remove(allocSale);
//colltoadd.Remove(allocPurch);
}
else
{
//Create new "split" item in the data source for the source table
PurchaseWS splitAllocPurch = new PurchaseWS { COMMODITY = allocPurch.COMMODITY, CONTRACTNUMBER = allocPurch.CONTRACTNUMBER, AMOUNT = allocPurch.AMOUNT - allocSale.AMOUNT, FORM = allocPurch.FORM, GRADE = allocPurch.GRADE, LOCATION = allocPurch.LOCATION, SHIP_DATE = allocPurch.SHIP_DATE, TRADEID = allocPurch.TRADEID, UNITS = allocPurch.UNITS };
//update the source table's selecteditem datacontext with the target allocation id
allocPurch.s_TRADEID = allocSale.TRADEID;
allocSale.p_TRADEID = allocPurch.TRADEID;
allocPurch.AMOUNT = allocSale.AMOUNT;
colltoadd.Insert(colltoadd.IndexOf(allocPurch) + 1, splitAllocPurch);
}
}