我想知道我是否应该只为我的视图模型创建一个类,或者我是否应该将我的属性和方法保存在单个类中。这是最好的做法吗?
以下示例显示了具有单独的视图模型类:
public class vmCustomer
{
public string FullName { get; set; }
public string Address { get; set; }
...
}
public class Customer
{
public vmCustomer GetCustomer(decimal id)
{
...
return customer;
}
}
以下是显示在单个类中包含我的属性和方法的示例:
public class Customer
{
public string FullName { get; set; }
public string Address { get; set; }
public Customer GetCustomer(decimal id)
{
...
return customer;
}
}
在OOP开发中有一个更好的首选吗?由于单一责任规则,SOLID原则是否会说单独的视图模型?
答案 0 :(得分:2)
ViewModel是视图和模型之间的“桥梁”。真实数据应该在模型中,在viewmodel中数据应该是格式化的,这样就可以绑定到视图。
同样按id选择customer应该在service类中,由viewmodel调用。
<div style="TEXT-ALIGN: justify; WIDTH: 100%; FONT-FAMILY: verdana, 'ms sans serif', arial; FONT-SIZE: 12px" id="AboutCompanySecDivEdit" jquery171011939482107256965="3">
<p>
<span style="FONT-FAMILY: verdana, 'ms sans serif', arial; FONT-SIZE: 12px">Incorporated in 2009, Hyderabad-based 3GTI, is an infrastructure provider of fiber optic in Andhra Pradesh. 3GTI owns a robust fiber network across Andhra Pradesh. 3GT) offers solutions for Enterprise Businesses
& service Providers. The company is promoted by Mrs.Yarla Geetha, Mrs. M Ratna Kumari & Mrs. Nusrat Moinuddin.</span>
</p>
</div>