Public Class User Public Property UserID As Integer Public Property FirstName As String //rest of the properties for user Public Sub Save() //save the details to the database End sub End Class
从我的UI(它在C#中)我这样做.
User objUser=new User(); objUser.FirstName="Happy"; objUser.Save();
一切正常.由于项目正在增长,我考虑尝试添加某种单元测试/依赖注入测试.用Google搜索并看到每个示例都使用Interfaces.我读了很多关于接口但不知道如何在我的编码中包含接口并使其遵循更好(可扩展和可测试)的模式.除了可测试性,它会给我一些其他优势吗?
有人可以给我一个示例如何做到这一点?
解决方法
摘录在这里:
The MVC pattern helps you create applications that separate the
different aspects of the application (input logic,business logic,and
UI logic),while providing a loose coupling between these elements.
The pattern specifies where each kind of logic should be located in
the application. The UI logic belongs in the view. Input logic belongs
in the controller. Business logic belongs in the model. This
separation helps you manage complexity when you build an application,
because it enables you to focus on one aspect of the implementation at
a time. For example,you can focus on the view without depending on
the business logic.The loose coupling between the three main components of an MVC application also promotes parallel development. For example,one developer can work on the view,a second developer can work on the controller logic,and a third developer can focus on the business logic in the model.