我正在尝试减少我的 asp.net 网络表单中存在的代码重复。这是从数据库加载的示例对象的样子。
Apartment
int id
decimal rent
bool callForPricing
int squareFeet
int beds
int baths
现在,我在几个不同的 asp.net 页面中从这个对象创建视图(即包含多个公寓的列表、详细视图等)。过去我所做的是创建另一个包装 Apartment 类的类。像这样的东西...
ApartmentView
Apartment apt
public virtual String Rent
{
get
{
if (apt.CallForPricing)
{
return "Call For Pricing";
}else{
return apt.Rent.ToString("C") + "/Month";
}
}
}
public virtual String BedsBathsSqFt
{
get
{
if (apt.squareFeet > 0)
{
return apt.beds + " Beds|" + apt.beds + " Beds|" + apt.SquareFeet + " sqft";
}else{
return apt.beds + " Beds|" + apt.beds + " Beds";
}
}
}
如您所见,我通常只是创建数据的字符串表示形式。我考虑过让 ApartmentView 类扩展 Apartment 类,但没有因为像“Rent”这样的重叠属性。我只是想知道人们通常如何处理这种情况。这是要使用的正确命名约定吗?