我们的软件架构师要求所有API操作都有自己的响应类,因为每个响应都可能略有不同。因此,我们基本上将Product封装在一个Base类中,并在需要时稍微定制。这是很好的建筑实践吗?我开始编程,看起来有点重复。另外,什么是更好的最佳替代方案呢?
产品类:
public class ProductDto
{
public int ProductId { get; set;},
public string ProductName { get; set;},
public string ProductDescription { get; set;},
public float SalesAmount { get; set;}
}BaseResponse:
public class BaseResponse<T>
{
[Required, ValidateObject]
public T Body { get; set; }
public bool HasError { get; set; }
public string Error { get; set; }
}个人回复:
public class CreateProductResponse : BaseResponse<ProductDto>
{
}
public class DeleteProductResponse : BaseResponse<int>
{
}
public class GetAllProductResponse : BaseResponse<IEnumerable<ProductDto>>
{
public int Count { get; set;};
}
public class GetProductResponse : BaseResponse<ProductDto>
{
}
public class UpdateProductResponse : BaseResponse<ProductDto>
{
public date DateUpdate { get; set;}
}发布于 2019-09-22 15:31:46
至少用目前的例子来说,我想说的是,这有点过分了。有许多派生类没有它自己的属性。也许在未来,同样的模式会继续下去。
更好的解决方案是将BaseResponse作为一个接口,以便更好地实现几个不同接口的相同属性的可扩展性。下面是更详细的信息。
发布于 2019-09-22 17:47:20
通过看到这段代码很难说出好/坏的架构实践。在我们的例子中,我们使用下面的模式并认为它是合理的。
public class BaseResponse
{
public bool HasError { get; set; }
public string Error { get; set; }
}
public class CreateProductResponse : BaseResponse
{
---
}
public class CreateProductDetailResponse : CreateProductResponse
{
---
}https://stackoverflow.com/questions/58048194
复制相似问题