开发 N 层应用程序.在什么方向? [英] Developing N-Tier App. In what direction?

查看:31
本文介绍了开发 N 层应用程序.在什么方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您正在实施一个用户故事,该用户故事需要在从 UI(或服务外观)到 DB 的所有层中进行更改.

Assuming the you are implementing a user story that requires changes in all layers from UI (or service facade) to DB.

你往哪个方向移动?

  • 从 UI 到业务层再到存储库到数据库?
  • 从数据库到存储库到业务层再到 UI?
  • 这取决于.(关于什么?)

推荐答案

我见过的对此类问题的最佳答案是由 Atomic Object 人员和他们的 Presenter First 模式.基本上,它是 MVP 模式的实现,其中(顾名思义)您从 Presenter 开始工作.

The best answer I've seen to this sort of question was supplied by the Atomic Object guys and their Presenter First pattern. Basically it is an implementation of the MVP pattern, in which (as the name suggests) you start working from the Presenter.

这为您提供了一个非常轻量级的对象(因为演示者基本上在那里将数据从模型编组到视图,并将事件从视图编组到模型),可以直接为您的用户操作集建模.在使用 Presenter 时,视图和模型通常被定义为接口并被模拟,因此您最初的重点是定义用户如何与您的对象进行交互.

This provides you with a very light-weight object (since the presenter is basically there to marshal data from the Model to the View, and events from the View to the Model) that can directly model your set of user actions. When working on the Presenter, the View and Model are typically defined as interfaces, and mocked, so your initial focus is on defining how the user is interacting with your objects.

我通常喜欢以这种方式工作,即使我没有采用严格的 MVP 模式.我发现关注用户交互有助于我创建更易于交互的业务对象.我们还在内部使用 Fitnesse 进行集成测试,我发现在构建我的业务对象有助于使事情专注于用户对故事的看法.

I generally like to work in this way, even if I'm not doing a strict MVP pattern. I find that focusing on user interaction helps me create business objects that are easier to interact with. We also use Fitnesse in house for integration testing, and I find that writing the fixtures for Fitnesse while building out my business objects helps keep things focused on the user's perspective of the story.

不过,我不得不说,当您从一个失败的 Fitnesse 测试开始,然后为该功能创建一个失败的单元测试时,您最终会得到一个非常有趣的 TDD 循环,然后按照自己的方式返回堆栈.在某些情况下,我还要编写数据库单元测试,因此在 Fitnesse 测试通过之前,还有另一层测试需要编写、失败和通过.

I have to say, though, that you end up with a pretty interesting TDD cycle when you start with a failing Fitnesse test, then create a failing Unit Test for that functionality, and work your way back up the stack. In some cases I'm also writing Database unit tests, so there is another layer of tests that get to be written, failed, and passed, before the Fitnesse tests pass.

这篇关于开发 N 层应用程序.在什么方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆