我应该先设计应用程序或模型(数据库)吗?

时间:2022-10-05 12:36:26

I am getting ready to start building a new web project in my spare time to bring to fruition an idea that has been bouncing around my head for a while.

我正准备在我的业余时间开始建立一个新的网络项目,以实现一个已经在我脑海中蹦蹦跳跳一段时间的想法。

I have never gotten down whether I am better off first building the model and then the consuming application or the other way around.

我从来没有忘记我是否更好地首先建立模型然后消费应用程序或其他方式。

What are the best practices? What would you build first and why?

什么是最佳做法?你会先建造什么?为什么?

I imagine that in general the application should generally drive the model, however the application like many websites really doesn't do much without the model.

我想,一般来说应用程序通常应该驱动模型,但是像许多网站这样的应用程序在没有模型的情况下确实没有太大作用。

For some reason I find it easier at times to think in terms of the model since the application is really just actions on the model. Is this a poor way of thinking about things?

出于某种原因,我发现有时更容易根据模型进行思考,因为应用程序实际上只是对模型的操作。这是一种思考问题的糟糕方式吗?

What advantages/disadvantages does each option have?

每个选项有哪些优点/缺点?

16 个解决方案

#1


26  

When you're building the whole application yourself, I would start with the user. What does the user want? What information do they need? That should drive the design of the application and model, not the other way round. When the model is designed first, there is a temptation to expose the user to it directly, which will rarely make sense.

当您自己构建整个应用程序时,我将从用户开始。用户想要什么?他们需要什么信息?这应该推动应用程序和模型的设计,而不是相反。当首先设计模型时,有一种诱惑是直接将用户暴露给它,这很少有意义。

#2


19  

Personally, after I know the requirements (formal or not), I design the data model to handle the requirements. Then build out from there, with the business layer, persistence, unit testing, and then finally the GUI.

就个人而言,在我了解了要求(正式与否)之后,我设计了数据模型来处理要求。然后从那里构建,包括业务层,持久性,单元测试,最后是GUI。

If your DB is designed properly the first time, everything should just flow.

如果您的数据库第一次设计正确,一切都应该流动。

EDIT-Please be aware, that I'm not implying that your business layer or GUI should be a direct reflection of your DB model. Sometimes it will be similar, sometimes it won't. But your DB model should be able to accomodate all requirements.

编辑 - 请注意,我并不是说您的业务层或GUI应该直接反映您的数据库模型。有时它会相似,有时则不会。但是您的数据库模型应该能够满足所有要求。

#3


11  

First of all, your database is not your Model, it is just the mechanism you use to persist your model. Your model is a set of business objects the encapsulate the state and logic used by the business, and may be used by other applications.

首先,您的数据库不是您的模型,它只是您用来持久保存模型的机制。您的模型是一组业务对象,它封装了业务使用的状态和逻辑,并且可以由其他应用程序使用。

I have found that most clients don't understand tables, columns, but do understand process and workflow. Therefore, I work with the client to mock up the UI and the page flow for the tasks that need to be addressed in the solution. From this, I create the business objects to hold the required data for the UI.

我发现大多数客户端不了解表,列,但了解流程和工作流程。因此,我与客户一起模拟用户界面和解决方案中需要解决的任务的页面流。从这里,我创建业务对象来保存UI所需的数据。

The controllers handle the page logic and page flow. I mock up a data repository to handle some sample data. This allow the client and I to iterate the UI and flow until we are satisfied. Usually, we discover better ways of doing things, and the some activities they thought important, add no value.

控制器处理页面逻辑和页面流。我模拟了一个数据存储库来处理一些示例数据。这允许客户端和我迭代UI并流动直到我们满意为止。通常,我们会发现更好的做事方式,以及他们认为重要的一些活动,不会增加任何价值。

Now is the time I work on the database and the data access logic. Waiting until this point reduces the need to rework database schema, stored procedures, and DAL code.

现在是我处理数据库和数据访问逻辑的时候了。等到这一点为止,减少了重新编写数据库模式,存储过程和DAL代码的需要。

This usually results in less code, a robust application, and a happy client. The triple crown.

这通常会导致更少的代码,强大的应用程序和愉快的客户端。三冠王。

Also, Unit Test everything. You will be making changes, and a good unit test set makes sure that you don't break other parts of your application when you make the changes.

另外,单元测试一切。您将进行更改,并且一个好的单元测试集确保您在进行更改时不会破坏应用程序的其他部分。

#4


9  

You know, I think I have to disagree with those that blindly put the design of the GUI ahead of the underlying data model. In a real business environment, running the business is not just about workflow - a huge component of business that revolves around data analysis and reporting. After all, how can you make decisions based on data you can't get to or understand? On top of this, when you sit down with a client, 90% of the time, they don't understand what their application needs to do, how it needs to be laid out and half the time, they don't even understand what functionality it requires.

你知道,我认为我必须不同意那些盲目地将GUI的设计置于底层数据模型之前的人。在真实的商业环境中,运营业务不仅仅与工作流程有关 - 工作流程是围绕数据分析和报告的重要业务组成部分。毕竟,您如何根据您无法获得或理解的数据做出决策?最重要的是,当你与客户坐下来时,90%的时间,他们不明白他们的应用程序需要做什么,需要如何布局和一半的时间,他们甚至不明白什么它需要的功能。

How do you analyse your data if your whole data model is just a persistence of on-screen data? How do you report on that? If you sit down with a database guru and tell them you want a report built from a data model that basically represents your ViewState they would quit and tell you to do it yourself - at least, if someone told me that I had to build a report based on that type of model, I'd quit and tell them to get someone else to do it.

如果整个数据模型只是屏幕数据的持久性,那么如何分析数据?你是如何报道的?如果你坐下来与数据库大师并告诉他们你想要一个基本上代表你的ViewState的数据模型构建的报告,他们会退出并告诉你自己做 - 至少,如果有人告诉我我必须建立一个报告基于那种类型的模型,我会放弃并告诉他们让其他人去做。

The GUI that sits on top of the data model is incidental and allows employees to interact with the data in the simplest most efficient manner. Bear in mind that software users aren't programmers, they don't think the way programmers or database architects do, and they don't do they work the way we work; nor do they want to. They want to be able to enter data easily and in the most logical manner according to their daily workflow. They want to be able to think, how much can I get done today so that when I go home, I don't have to take work with me, they want to go on vacation without worrying if the new guy will be able to keep up with the flow or if they'll be able to understand the software.

位于数据模型之上的GUI是偶然的,允许员工以最简单,最有效的方式与数据交互。请记住,软件用户不是程序员,他们不会像程序员或数据库架构师那样思考,他们不会按照我们的工作方式工作;他们也不想。他们希望能够根据日常工作流程以最合理的方式轻松输入数据。他们希望能够思考,今天能完成多少工作,这样当我回家时,我不需要和我一起工作,他们想去度假而不用担心新人是否能够保持顺其自然,或者他们是否能够理解软件。

Business owners want to be able to get the data out in the simplest most efficient manner, they want reports written at a moment's notice, and they want that data represented logically, efficiently and representatively of whatever model they choose for the current report. They care little about workflow, they don't need to know how many departments this piece of data flowed through, where it came from, how it got to where it is now. They want to know what the piece of data is, what it represents and what does it mean to the business as a whole.

企业所有者希望能够以最简单,最有效的方式获取数据,他们希望立即写入报告,并希望数据以逻辑,有效和代表性的方式表示他们为当前报告选择的任何模型。他们对工作流程几乎不关心,他们不需要知道这条数据流经多少个部门,它来自哪里,如何到达现在的位置。他们想知道这些数据是什么,它代表什么以及它对整个企业意味着什么。

To a business owner, the data is far more important than the piece of software. To the end user who has pressure to do ten times more in ten times less time, the software needs to provide them with a means of getting as much data into the database as possible in the shortest amount of time.

对于企业所有者而言,数据远比软件重要。对于压力要在十倍的时间内做十倍以上的压力的最终用户,软件需要为他们提供在最短的时间内尽可能多地将数据输入数据库的方法。

So how do you decide which to design first, the GUI or the data model? How much money is going to be saved in the longer term? Does the company have 500 users entering data into this piece of software and are they doing it in the most efficient manner? Does the company have 500 report writers and can they get at the data quickly and efficiently? How long is a piece of string?

那么您如何决定首先设计哪个,GUI或数据模型?从长远来看,将节省多少钱?公司是否有500名用户在这个软件中输入数据,他们是否以最有效的方式进行操作?该公司是否有500名报告编写者,他们能否快速有效地获取数据?一段绳子有多长?

Design your data model for the data analysts - make it as clean, efficient as simple as possible to get the data out in a comprehensive format.

为数据分析人员设计数据模型 - 使其尽可能简洁,高效,以全面的格式输出数据。

Design your GUI for the end users and make it as clean, simple and efficient as it can be for those users to get as much data into your database as quickly and as simply as possible without having to be a rocket scientist. Frequently end users are barely computer literate in comparison to those writing the software and extracting the data.

为最终用户设计GUI并使其干净,简单和高效,因为这些用户可以尽可能快速,简单地将尽可能多的数据输入数据库,而无需成为火箭科学家。与编写软件和提取数据的用户相比,最终用户通常几乎没有计算机知识。

From the outset, always keep in mind how you're going to wire the two together because if you don't, you'll end up with two ends and no way to provide a middle and your project will fall to pieces...

从一开始,要始终牢记你要如何将两者连接在一起,因为如果你不这样做,你最终会有两端而无法提供中间,你的项目将会崩溃......

More money is wasted putting data into a system and getting the data out than writing the software that does the wiring between the two ends. A team of developers doesn't cost nearly what it costs a company whose users are inputting inaccurate data inefficiently and poor quality reports because the data analysts can't get at that inaccurate data efficiently and spend a week writing a report that realistically shouldn't be taking more than an hour or two and when it is written is no help anyway.

浪费更多资金将数据放入系统并获取数据,而不是编写在两端之间进行连接的软件。由于数据分析师无法有效地获取这些不准确的数据并花费一周的时间编写一份实际上不应该生成的报告,因此开发人员团队的成本几乎不会高于用户输入不准确的数据和低质量报告的公司的成本。花了一两个多小时,写完之时无论如何都没有用。

#5


4  

How about both?

这两个怎么样?

Another approach is "feature-based" development - build a vertical slice through the application, just enough at the model, persistence and interface levels to get a feature working completely. This might be something as simple as logging in, or editing a single object.

另一种方法是“基于特征的”开发 - 通过应用程序构建一个垂直切片,在模型,持久性和接口级别上足以使功能完全正常工作。这可能就像登录或编辑单个对象一样简单。

This approach means that:

这种方法意味着:

  • you get to build a small chunk of both model and application together up front;
  • 你可以在前面一起构建一小部分模型和应用程序;

  • you quickly discover any danger areas in the stack of technologies and designs you've chosen;
  • 您可以快速发现您所选择的技术和设计堆栈中的任何危险区域;

  • you rapidly have something you can show to people for comments;
  • 你很快就会有一些东西可以向人们展示以征求意见;

  • you avoid the fallacy that anything gets designed right first time...
  • 你避免了第一次正确设计任何东西的谬论......

#6


4  

FWIW, one of the best remembered parts of *s's The Mythical Man Month is this:

FWIW,布鲁克斯的神话人月最值得纪念的部分之一是:

Show me your flow charts and conceal your tables and I shall continue to be mystified, show me your tables and I won't usually need your flow charts; they'll be obvious.

告诉我你的流程图并隐藏你的桌子,我将继续神秘化,向我展示你的桌子,我通常不需要你的流程图;他们会很明显。

#7


3  

Most web applications don't do much more than just processing and presenting different kinds of data.

大多数Web应用程序不仅仅处理和呈现不同类型的数据。

I would start with exactly that: What data do I want to process?

我会从那开始:我想要处理哪些数据?

After that, you can start modelling how this data will fit into a database best.

之后,您可以开始建模这些数据最适合数据库的方式。

Then you should also think about how you access this data-does it give you any hints for optimization in the storage?

那么您还应该考虑如何访问这些数据 - 它是否为您提供了存储优化的任何提示?

I would design the application itself either at the end or even parallel to it. The application design should be independent from the database model. It's only the code itself which will in the end access the database.

我会在最后设计应用程序本身,或者甚至与它平行。应用程序设计应独立于数据库模型。它只是代码本身最终将访问数据库。

But, web applications also tend to grow. So an evolutionary model, where you add new fields or tables to the database and build new code around it, is very common.

但是,Web应用程序也趋于增长。因此,在数据库中添加新字段或表并在其周围构建新代码的进化模型非常常见。

#8


2  

You don't want your object model to be constrained by a database design. The database should be a persistence implementation of your object model, which is the one that rules. You can wrap your application around your object model, and also derive the persistence model.

您不希望对象模型受数据库设计的约束。数据库应该是对象模型的持久性实现,它是一个规则的实现。您可以围绕对象模型包装应用程序,还可以派生持久性模型。

#9


2  

You could start by designing the interface between the application and model and writing unit tests for how the interface should behave. I usually take the more agile approach and do only a little upfront design before I jump into the code (see: Pragmatic Programmers From Journeyman to Master Tracer Bullets concept).

您可以从设计应用程序和模型之间的接口开始,并编写单元测试,以了解接口的行为方式。在进入代码之前,我通常采用更敏捷的方法并且只做一点前期设计(参见:实用程序员从Journeyman到Master Tracer Bullets概念)。

#10


2  

According to Martin Fowler which most skilled developers recognize as one of the "authorities" in these questions you design your OO hierarchy first and then "map" the objects into your database using e.g. the ActiveRecord design pattern...

根据Martin Fowler的说法,大多数熟练的开发人员都认为这些问题中的“权威”之一是您首先设计您的OO层次结构,然后使用例如“对象”将对象“映射”到您的数据库中。 ActiveRecord设计模式......

#11


1  

Well, to an extent the requirements must come first. The database is the servant of your requirements after all, not the other way around.

嗯,在某种程度上,要求必须先行。毕竟数据库是你需求的仆人,而不是相反。

It seems to me that what you're really asking is: should you design the application completely before you start on the database (and then write code after that)?

在我看来,你真正要问的是:你应该在开始使用数据库之前完全设计应用程序(之后再编写代码)吗?

My answer is no. It's better to jump in and get moving quickly.

我的回答是否定的。最好跳进去快速行动。

I would probably design the app in broad strokes and then use an iterative approach. Which is an idea from Agile. There is a lot out there on this subject.

我可能会广泛设计应用程序,然后使用迭代方法。这是敏捷的一个想法。关于这个问题有很多。

Now if this was a two year project with 20 developers, stakeholders, and a budget, things would be somewhat different... But perhaps not as different as you think! The more complexity you're dealing with, the harder it becomes create a perfect, monolithic plan up front.

现在,如果这是一个为期两年的项目,有20位开发人员,利益相关者和预算,事情就会有所不同......但也许并不像你想象的那么不同!您处理的复杂性越高,就越难以预先创建完美的整体计划。

Some people say there is a point where it actually becomes impossible.

有人说有一点实际上变得不可能。

#12


1  

It's one that works either way, but personally I'm leaning toward designing from the UI back more and more.

这是一种无论哪种方式都有效,但我个人倾向于越来越多地从UI设计。

The main reason comes down to being able to create supporting automated tests.

主要原因归结为能够创建支持自动化测试。

One of the strengths of automated testing is the flexibility to refactor and change your code as you go. However the UI is typically the hardest to change, and the one that often requires the most work to get right.

自动化测试的优势之一是可以灵活地重构和更改代码。然而,UI通常是最难改变的,并且通常需要最多的工作才能正确。

So for that reason, I advocate designing the UI, get it as close as possible to the finished version, then move backwards creating your middle and back end to support the operations carried out in that GUI.

因此,我主张设计UI,尽可能接近完成版本,然后向后移动创建中间和后端以支持在GUI中执行的操作。

With a relatively stable (and difficult to test) UI in place, you're free to mold the other layers with a lot more flexibility once you've got good test coverage for them.

通过相对稳定(且难以测试)的UI,一旦您获得了良好的测试覆盖率,您就可以更*地模塑其他层。

If you design from the database up, you'll end up with a stable, easy to test database, and a LOT of messing around getting the GUI just right to match what you've done with the DB - which ends up taking a lot longer as you're making the most changes to the level of the system that is the hardest to test and has the lowest test coverage.

如果你从数据库中进行设计,你最终会得到一个稳定,易于测试的数据库,并且很多人都在努力使GUI与你在数据库中完成的工作相匹配 - 这最终会占用很多更长时间,因为您对最难测试的系统级别进行了最大的更改,并且测试覆盖率最低。

Plus the fact that DB driven designed apps end up having no personality and are difficult to use. They look like the same MS Access form for each screen, except with different fields.

此外,数据库驱动设计的应用程序最终没有个性,难以使用。除了不同的字段外,它们看起来与每个屏幕的MS Access窗体相同。

#13


1  

From experience, designing the database first (based on requirements), can lead to things going very smoothly.

根据经验,首先设计数据库(基于要求),可以使事情进展顺利。

This is especially true if your data does not just relate to data entered in the UI, but may include pre-existing data related to or imported for the project.

如果您的数据不仅与UI中输入的数据相关,而且可能包括与项目相关或导入的预先存在的数据,则尤其如此。

On a mid-size project I may go through 100+ iterations of the DB using an ERD diagramming tool like Erwin or Power SQL. Then, click the forward-engineer button to get the DDL.

在中型项目中,我可以使用Erwin或Power SQL等ERD图表工具进行100多次迭代。然后,单击forward-engineer按钮以获取DDL。

The domain objects will typically look a lot like your main tables, however they will often have collections where the DB has look-up tables, etc. Also your domain objects may have other objects in them for organizational purposes, etc.

域对象通常看起来很像主表,但是它们通常具有DB具有查找表等的集合。此外,您的域对象可能还有其他对象用于组织目的等。

Then wire up a DAL either hand-rolled or ORM of your choice.

然后用您自己选择的手动或ORM连接DAL。

Thing is, none of the tools designed to automate this process seem to do it 100%. In a code utopia, I guess you could just create the DB model and have the perfect domain model created or vice versa, and than get a perfect ORM with a few clicks. In reality, this is a lot harder than it sounds, and subtle issues can arise like performance and flexibility.

事实上,设计用于自动化此过程的工具似乎都没有100%完成。在代码乌托邦中,我想你可以创建数据库模型并创建完美的域模型,反之亦然,而不是通过几次点击获得完美的ORM。实际上,这比听起来要困难得多,并且会出现类似性能和灵活性等细微问题。

#14


0  

My tactic is roughly this:

我的策略大致如下:

Read the requirements, and write down all nouns or "players" in the document. These are usually 80% of the things you need to store or interact with.

阅读要求,并记下文档中的所有名词或“玩家”。这些通常是您需要存储或与之交互的80%。

With these things on a sheet of paper, read the requirements again and see if you can find that the things you have on paper can actually be used to do the job.

将这些东西放在一张纸上,再次阅读要求,看看你是否能够发现纸上的东西实际上可以用来完成这项工作。

The, find their attributes and make a data model. Try to fit that into the database. Build up from there.

,找到他们的属性并制作数据模型。尝试将其纳入数据库。从那里建立起来。

For web applications, this usually works for me (even for consierable size applications). As you've noticed, I didn't use terms like UML or ERD. These are just tools for communicating the model in your head with others. Powerpoint can do that, too. It's the quality of end product that counts.

对于Web应用程序,这通常适用于我(即使对于可用的大小应用程序)。正如您所注意到的,我没有使用像UML或ERD这样的术语。这些只是用于与其他人沟通模型的工具。 Powerpoint也可以做到这一点。重要的是最终产品的质量。

#15


0  

For me it depends previous experience with the problem domain.

对我而言,这取决于之前对问题域的体验。

If I have done this sort of app before, I am more likely to take the time to clarify the data model first and then start building code on top of that.

如果我以前做过这种应用程序,我更有可能先花时间澄清数据模型,然后开始构建代码。

On a first-time project I am more likely to just jump in with coding, whipping up dummy data as needed and learning about hidden dimensions of the problem domain as I go. Not uncommonly there are data categories that would have been difficult to anticipate. When I discover these, I revise the data model and continue on. Often this approach begins with coding up a script to build the database and populate it. That way, on subsequent iterations, I just modify the db-build script, run it, and I'm back in business.

在第一次项目中,我更有可能只是跳入编码,根据需要掀起虚拟数据,并随时了解问题域的隐藏维度。很少有数据类别难以预料。当我发现这些时,我会修改数据模型并继续。通常,这种方法始于编写脚本以构建数据库并填充它。这样,在后续迭代中,我只修改db-build脚本,运行它,然后我重新开始工作。

#16


0  

This is the age old question. The answer, like every CS answer is that it depends. 90% of the applications that you write are just forms over data. In many of these applications, you will have legacy applications with data that you have to port over an go from there. Therefore, whether you like it or not, the Data/Database is a constricting factor and it drives whatever you do. It’s not just a place to store your domain objects, it is your domain, even though that’s not the “right” way to do things.

这是一个古老的问题。答案,就像每个CS答案一样,它取决于它。您编写的应用程序中有90%只是表单而非数据。在许多这些应用程序中,您将拥有遗留应用程序,其中包含您必须从那里移植的数据。因此,无论您是否喜欢,数据/数据库都是一个限制因素,它会驱动您所做的一切。它不仅仅是存储域对象的地方,它也是您的域名,即使这不是“正确”的做事方式。

In most cases, I’ve designed my data model first in a way that takes the existing data and organizes it into the relational model. I then do basic screen design. Then I build my anemic Active Record type business objects to wire them up. This is by no means the best way to design software, but in most cases, it’s the way that things will be done or have been done. In these cases, your business objects really are just containers for data with business logic around them to wire them up to the screens and insure data integrity and screen security. This sucks, but it is what it is.

在大多数情况下,我首先以一种获取现有数据并将其组织到关系模型中的方式设计我的数据模型。然后我做基本的屏幕设计。然后我构建我的贫血Active Record类型业务对象来连接它们。这绝不是设计软件的最佳方式,但在大多数情况下,这是事情将要完成或已经完成的方式。在这些情况下,您的业务对象实际上只是具有业务逻辑的数据的容器,可以将它们连接到屏幕并确保数据完整性和屏幕安全性。这很糟糕,但事实就是如此。

If screen interactions are the most important thing, then maybe designing the screen first and then have you other objects depend on that will be your best bet.

如果屏幕交互是最重要的事情,那么可能首先设计屏幕,然后让你依赖于其他对象,这将是你最好的选择。

If you are lucky enough to have a Greenfield project where the domain is integral in the application and the database is merely a persistence mechanism for your domain objects, then I would develop the domain objects first using Domain Driven Design in a TDD manor and develop the screens and the database around the domain objects. I would love to code like this more often, but you don’t always get the opportunity in most places.

如果你有幸拥有一个Greenfield项目,其中域是应用程序中不可或缺的,而数据库只是域对象的持久性机制,那么我将首先使用TDD庄园中的域驱动设计开发域对象并开发屏幕和域对象周围的数据库。我希望更频繁地编码这样的代码,但是你并不总是在大多数地方获得机会。

Note: Stack Overflow is designed in a Database as the Model way, so it can't be that evil.

注意:Stack Overflow在数据库中被设计为模型方式,所以它不是那么邪恶。

#1


26  

When you're building the whole application yourself, I would start with the user. What does the user want? What information do they need? That should drive the design of the application and model, not the other way round. When the model is designed first, there is a temptation to expose the user to it directly, which will rarely make sense.

当您自己构建整个应用程序时,我将从用户开始。用户想要什么?他们需要什么信息?这应该推动应用程序和模型的设计,而不是相反。当首先设计模型时,有一种诱惑是直接将用户暴露给它,这很少有意义。

#2


19  

Personally, after I know the requirements (formal or not), I design the data model to handle the requirements. Then build out from there, with the business layer, persistence, unit testing, and then finally the GUI.

就个人而言,在我了解了要求(正式与否)之后,我设计了数据模型来处理要求。然后从那里构建,包括业务层,持久性,单元测试,最后是GUI。

If your DB is designed properly the first time, everything should just flow.

如果您的数据库第一次设计正确,一切都应该流动。

EDIT-Please be aware, that I'm not implying that your business layer or GUI should be a direct reflection of your DB model. Sometimes it will be similar, sometimes it won't. But your DB model should be able to accomodate all requirements.

编辑 - 请注意,我并不是说您的业务层或GUI应该直接反映您的数据库模型。有时它会相似,有时则不会。但是您的数据库模型应该能够满足所有要求。

#3


11  

First of all, your database is not your Model, it is just the mechanism you use to persist your model. Your model is a set of business objects the encapsulate the state and logic used by the business, and may be used by other applications.

首先,您的数据库不是您的模型,它只是您用来持久保存模型的机制。您的模型是一组业务对象,它封装了业务使用的状态和逻辑,并且可以由其他应用程序使用。

I have found that most clients don't understand tables, columns, but do understand process and workflow. Therefore, I work with the client to mock up the UI and the page flow for the tasks that need to be addressed in the solution. From this, I create the business objects to hold the required data for the UI.

我发现大多数客户端不了解表,列,但了解流程和工作流程。因此,我与客户一起模拟用户界面和解决方案中需要解决的任务的页面流。从这里,我创建业务对象来保存UI所需的数据。

The controllers handle the page logic and page flow. I mock up a data repository to handle some sample data. This allow the client and I to iterate the UI and flow until we are satisfied. Usually, we discover better ways of doing things, and the some activities they thought important, add no value.

控制器处理页面逻辑和页面流。我模拟了一个数据存储库来处理一些示例数据。这允许客户端和我迭代UI并流动直到我们满意为止。通常,我们会发现更好的做事方式,以及他们认为重要的一些活动,不会增加任何价值。

Now is the time I work on the database and the data access logic. Waiting until this point reduces the need to rework database schema, stored procedures, and DAL code.

现在是我处理数据库和数据访问逻辑的时候了。等到这一点为止,减少了重新编写数据库模式,存储过程和DAL代码的需要。

This usually results in less code, a robust application, and a happy client. The triple crown.

这通常会导致更少的代码,强大的应用程序和愉快的客户端。三冠王。

Also, Unit Test everything. You will be making changes, and a good unit test set makes sure that you don't break other parts of your application when you make the changes.

另外,单元测试一切。您将进行更改,并且一个好的单元测试集确保您在进行更改时不会破坏应用程序的其他部分。

#4


9  

You know, I think I have to disagree with those that blindly put the design of the GUI ahead of the underlying data model. In a real business environment, running the business is not just about workflow - a huge component of business that revolves around data analysis and reporting. After all, how can you make decisions based on data you can't get to or understand? On top of this, when you sit down with a client, 90% of the time, they don't understand what their application needs to do, how it needs to be laid out and half the time, they don't even understand what functionality it requires.

你知道,我认为我必须不同意那些盲目地将GUI的设计置于底层数据模型之前的人。在真实的商业环境中,运营业务不仅仅与工作流程有关 - 工作流程是围绕数据分析和报告的重要业务组成部分。毕竟,您如何根据您无法获得或理解的数据做出决策?最重要的是,当你与客户坐下来时,90%的时间,他们不明白他们的应用程序需要做什么,需要如何布局和一半的时间,他们甚至不明白什么它需要的功能。

How do you analyse your data if your whole data model is just a persistence of on-screen data? How do you report on that? If you sit down with a database guru and tell them you want a report built from a data model that basically represents your ViewState they would quit and tell you to do it yourself - at least, if someone told me that I had to build a report based on that type of model, I'd quit and tell them to get someone else to do it.

如果整个数据模型只是屏幕数据的持久性,那么如何分析数据?你是如何报道的?如果你坐下来与数据库大师并告诉他们你想要一个基本上代表你的ViewState的数据模型构建的报告,他们会退出并告诉你自己做 - 至少,如果有人告诉我我必须建立一个报告基于那种类型的模型,我会放弃并告诉他们让其他人去做。

The GUI that sits on top of the data model is incidental and allows employees to interact with the data in the simplest most efficient manner. Bear in mind that software users aren't programmers, they don't think the way programmers or database architects do, and they don't do they work the way we work; nor do they want to. They want to be able to enter data easily and in the most logical manner according to their daily workflow. They want to be able to think, how much can I get done today so that when I go home, I don't have to take work with me, they want to go on vacation without worrying if the new guy will be able to keep up with the flow or if they'll be able to understand the software.

位于数据模型之上的GUI是偶然的,允许员工以最简单,最有效的方式与数据交互。请记住,软件用户不是程序员,他们不会像程序员或数据库架构师那样思考,他们不会按照我们的工作方式工作;他们也不想。他们希望能够根据日常工作流程以最合理的方式轻松输入数据。他们希望能够思考,今天能完成多少工作,这样当我回家时,我不需要和我一起工作,他们想去度假而不用担心新人是否能够保持顺其自然,或者他们是否能够理解软件。

Business owners want to be able to get the data out in the simplest most efficient manner, they want reports written at a moment's notice, and they want that data represented logically, efficiently and representatively of whatever model they choose for the current report. They care little about workflow, they don't need to know how many departments this piece of data flowed through, where it came from, how it got to where it is now. They want to know what the piece of data is, what it represents and what does it mean to the business as a whole.

企业所有者希望能够以最简单,最有效的方式获取数据,他们希望立即写入报告,并希望数据以逻辑,有效和代表性的方式表示他们为当前报告选择的任何模型。他们对工作流程几乎不关心,他们不需要知道这条数据流经多少个部门,它来自哪里,如何到达现在的位置。他们想知道这些数据是什么,它代表什么以及它对整个企业意味着什么。

To a business owner, the data is far more important than the piece of software. To the end user who has pressure to do ten times more in ten times less time, the software needs to provide them with a means of getting as much data into the database as possible in the shortest amount of time.

对于企业所有者而言,数据远比软件重要。对于压力要在十倍的时间内做十倍以上的压力的最终用户,软件需要为他们提供在最短的时间内尽可能多地将数据输入数据库的方法。

So how do you decide which to design first, the GUI or the data model? How much money is going to be saved in the longer term? Does the company have 500 users entering data into this piece of software and are they doing it in the most efficient manner? Does the company have 500 report writers and can they get at the data quickly and efficiently? How long is a piece of string?

那么您如何决定首先设计哪个,GUI或数据模型?从长远来看,将节省多少钱?公司是否有500名用户在这个软件中输入数据,他们是否以最有效的方式进行操作?该公司是否有500名报告编写者,他们能否快速有效地获取数据?一段绳子有多长?

Design your data model for the data analysts - make it as clean, efficient as simple as possible to get the data out in a comprehensive format.

为数据分析人员设计数据模型 - 使其尽可能简洁,高效,以全面的格式输出数据。

Design your GUI for the end users and make it as clean, simple and efficient as it can be for those users to get as much data into your database as quickly and as simply as possible without having to be a rocket scientist. Frequently end users are barely computer literate in comparison to those writing the software and extracting the data.

为最终用户设计GUI并使其干净,简单和高效,因为这些用户可以尽可能快速,简单地将尽可能多的数据输入数据库,而无需成为火箭科学家。与编写软件和提取数据的用户相比,最终用户通常几乎没有计算机知识。

From the outset, always keep in mind how you're going to wire the two together because if you don't, you'll end up with two ends and no way to provide a middle and your project will fall to pieces...

从一开始,要始终牢记你要如何将两者连接在一起,因为如果你不这样做,你最终会有两端而无法提供中间,你的项目将会崩溃......

More money is wasted putting data into a system and getting the data out than writing the software that does the wiring between the two ends. A team of developers doesn't cost nearly what it costs a company whose users are inputting inaccurate data inefficiently and poor quality reports because the data analysts can't get at that inaccurate data efficiently and spend a week writing a report that realistically shouldn't be taking more than an hour or two and when it is written is no help anyway.

浪费更多资金将数据放入系统并获取数据,而不是编写在两端之间进行连接的软件。由于数据分析师无法有效地获取这些不准确的数据并花费一周的时间编写一份实际上不应该生成的报告,因此开发人员团队的成本几乎不会高于用户输入不准确的数据和低质量报告的公司的成本。花了一两个多小时,写完之时无论如何都没有用。

#5


4  

How about both?

这两个怎么样?

Another approach is "feature-based" development - build a vertical slice through the application, just enough at the model, persistence and interface levels to get a feature working completely. This might be something as simple as logging in, or editing a single object.

另一种方法是“基于特征的”开发 - 通过应用程序构建一个垂直切片,在模型,持久性和接口级别上足以使功能完全正常工作。这可能就像登录或编辑单个对象一样简单。

This approach means that:

这种方法意味着:

  • you get to build a small chunk of both model and application together up front;
  • 你可以在前面一起构建一小部分模型和应用程序;

  • you quickly discover any danger areas in the stack of technologies and designs you've chosen;
  • 您可以快速发现您所选择的技术和设计堆栈中的任何危险区域;

  • you rapidly have something you can show to people for comments;
  • 你很快就会有一些东西可以向人们展示以征求意见;

  • you avoid the fallacy that anything gets designed right first time...
  • 你避免了第一次正确设计任何东西的谬论......

#6


4  

FWIW, one of the best remembered parts of *s's The Mythical Man Month is this:

FWIW,布鲁克斯的神话人月最值得纪念的部分之一是:

Show me your flow charts and conceal your tables and I shall continue to be mystified, show me your tables and I won't usually need your flow charts; they'll be obvious.

告诉我你的流程图并隐藏你的桌子,我将继续神秘化,向我展示你的桌子,我通常不需要你的流程图;他们会很明显。

#7


3  

Most web applications don't do much more than just processing and presenting different kinds of data.

大多数Web应用程序不仅仅处理和呈现不同类型的数据。

I would start with exactly that: What data do I want to process?

我会从那开始:我想要处理哪些数据?

After that, you can start modelling how this data will fit into a database best.

之后,您可以开始建模这些数据最适合数据库的方式。

Then you should also think about how you access this data-does it give you any hints for optimization in the storage?

那么您还应该考虑如何访问这些数据 - 它是否为您提供了存储优化的任何提示?

I would design the application itself either at the end or even parallel to it. The application design should be independent from the database model. It's only the code itself which will in the end access the database.

我会在最后设计应用程序本身,或者甚至与它平行。应用程序设计应独立于数据库模型。它只是代码本身最终将访问数据库。

But, web applications also tend to grow. So an evolutionary model, where you add new fields or tables to the database and build new code around it, is very common.

但是,Web应用程序也趋于增长。因此,在数据库中添加新字段或表并在其周围构建新代码的进化模型非常常见。

#8


2  

You don't want your object model to be constrained by a database design. The database should be a persistence implementation of your object model, which is the one that rules. You can wrap your application around your object model, and also derive the persistence model.

您不希望对象模型受数据库设计的约束。数据库应该是对象模型的持久性实现,它是一个规则的实现。您可以围绕对象模型包装应用程序,还可以派生持久性模型。

#9


2  

You could start by designing the interface between the application and model and writing unit tests for how the interface should behave. I usually take the more agile approach and do only a little upfront design before I jump into the code (see: Pragmatic Programmers From Journeyman to Master Tracer Bullets concept).

您可以从设计应用程序和模型之间的接口开始,并编写单元测试,以了解接口的行为方式。在进入代码之前,我通常采用更敏捷的方法并且只做一点前期设计(参见:实用程序员从Journeyman到Master Tracer Bullets概念)。

#10


2  

According to Martin Fowler which most skilled developers recognize as one of the "authorities" in these questions you design your OO hierarchy first and then "map" the objects into your database using e.g. the ActiveRecord design pattern...

根据Martin Fowler的说法,大多数熟练的开发人员都认为这些问题中的“权威”之一是您首先设计您的OO层次结构,然后使用例如“对象”将对象“映射”到您的数据库中。 ActiveRecord设计模式......

#11


1  

Well, to an extent the requirements must come first. The database is the servant of your requirements after all, not the other way around.

嗯,在某种程度上,要求必须先行。毕竟数据库是你需求的仆人,而不是相反。

It seems to me that what you're really asking is: should you design the application completely before you start on the database (and then write code after that)?

在我看来,你真正要问的是:你应该在开始使用数据库之前完全设计应用程序(之后再编写代码)吗?

My answer is no. It's better to jump in and get moving quickly.

我的回答是否定的。最好跳进去快速行动。

I would probably design the app in broad strokes and then use an iterative approach. Which is an idea from Agile. There is a lot out there on this subject.

我可能会广泛设计应用程序,然后使用迭代方法。这是敏捷的一个想法。关于这个问题有很多。

Now if this was a two year project with 20 developers, stakeholders, and a budget, things would be somewhat different... But perhaps not as different as you think! The more complexity you're dealing with, the harder it becomes create a perfect, monolithic plan up front.

现在,如果这是一个为期两年的项目,有20位开发人员,利益相关者和预算,事情就会有所不同......但也许并不像你想象的那么不同!您处理的复杂性越高,就越难以预先创建完美的整体计划。

Some people say there is a point where it actually becomes impossible.

有人说有一点实际上变得不可能。

#12


1  

It's one that works either way, but personally I'm leaning toward designing from the UI back more and more.

这是一种无论哪种方式都有效,但我个人倾向于越来越多地从UI设计。

The main reason comes down to being able to create supporting automated tests.

主要原因归结为能够创建支持自动化测试。

One of the strengths of automated testing is the flexibility to refactor and change your code as you go. However the UI is typically the hardest to change, and the one that often requires the most work to get right.

自动化测试的优势之一是可以灵活地重构和更改代码。然而,UI通常是最难改变的,并且通常需要最多的工作才能正确。

So for that reason, I advocate designing the UI, get it as close as possible to the finished version, then move backwards creating your middle and back end to support the operations carried out in that GUI.

因此,我主张设计UI,尽可能接近完成版本,然后向后移动创建中间和后端以支持在GUI中执行的操作。

With a relatively stable (and difficult to test) UI in place, you're free to mold the other layers with a lot more flexibility once you've got good test coverage for them.

通过相对稳定(且难以测试)的UI,一旦您获得了良好的测试覆盖率,您就可以更*地模塑其他层。

If you design from the database up, you'll end up with a stable, easy to test database, and a LOT of messing around getting the GUI just right to match what you've done with the DB - which ends up taking a lot longer as you're making the most changes to the level of the system that is the hardest to test and has the lowest test coverage.

如果你从数据库中进行设计,你最终会得到一个稳定,易于测试的数据库,并且很多人都在努力使GUI与你在数据库中完成的工作相匹配 - 这最终会占用很多更长时间,因为您对最难测试的系统级别进行了最大的更改,并且测试覆盖率最低。

Plus the fact that DB driven designed apps end up having no personality and are difficult to use. They look like the same MS Access form for each screen, except with different fields.

此外,数据库驱动设计的应用程序最终没有个性,难以使用。除了不同的字段外,它们看起来与每个屏幕的MS Access窗体相同。

#13


1  

From experience, designing the database first (based on requirements), can lead to things going very smoothly.

根据经验,首先设计数据库(基于要求),可以使事情进展顺利。

This is especially true if your data does not just relate to data entered in the UI, but may include pre-existing data related to or imported for the project.

如果您的数据不仅与UI中输入的数据相关,而且可能包括与项目相关或导入的预先存在的数据,则尤其如此。

On a mid-size project I may go through 100+ iterations of the DB using an ERD diagramming tool like Erwin or Power SQL. Then, click the forward-engineer button to get the DDL.

在中型项目中,我可以使用Erwin或Power SQL等ERD图表工具进行100多次迭代。然后,单击forward-engineer按钮以获取DDL。

The domain objects will typically look a lot like your main tables, however they will often have collections where the DB has look-up tables, etc. Also your domain objects may have other objects in them for organizational purposes, etc.

域对象通常看起来很像主表,但是它们通常具有DB具有查找表等的集合。此外,您的域对象可能还有其他对象用于组织目的等。

Then wire up a DAL either hand-rolled or ORM of your choice.

然后用您自己选择的手动或ORM连接DAL。

Thing is, none of the tools designed to automate this process seem to do it 100%. In a code utopia, I guess you could just create the DB model and have the perfect domain model created or vice versa, and than get a perfect ORM with a few clicks. In reality, this is a lot harder than it sounds, and subtle issues can arise like performance and flexibility.

事实上,设计用于自动化此过程的工具似乎都没有100%完成。在代码乌托邦中,我想你可以创建数据库模型并创建完美的域模型,反之亦然,而不是通过几次点击获得完美的ORM。实际上,这比听起来要困难得多,并且会出现类似性能和灵活性等细微问题。

#14


0  

My tactic is roughly this:

我的策略大致如下:

Read the requirements, and write down all nouns or "players" in the document. These are usually 80% of the things you need to store or interact with.

阅读要求,并记下文档中的所有名词或“玩家”。这些通常是您需要存储或与之交互的80%。

With these things on a sheet of paper, read the requirements again and see if you can find that the things you have on paper can actually be used to do the job.

将这些东西放在一张纸上,再次阅读要求,看看你是否能够发现纸上的东西实际上可以用来完成这项工作。

The, find their attributes and make a data model. Try to fit that into the database. Build up from there.

,找到他们的属性并制作数据模型。尝试将其纳入数据库。从那里建立起来。

For web applications, this usually works for me (even for consierable size applications). As you've noticed, I didn't use terms like UML or ERD. These are just tools for communicating the model in your head with others. Powerpoint can do that, too. It's the quality of end product that counts.

对于Web应用程序,这通常适用于我(即使对于可用的大小应用程序)。正如您所注意到的,我没有使用像UML或ERD这样的术语。这些只是用于与其他人沟通模型的工具。 Powerpoint也可以做到这一点。重要的是最终产品的质量。

#15


0  

For me it depends previous experience with the problem domain.

对我而言,这取决于之前对问题域的体验。

If I have done this sort of app before, I am more likely to take the time to clarify the data model first and then start building code on top of that.

如果我以前做过这种应用程序,我更有可能先花时间澄清数据模型,然后开始构建代码。

On a first-time project I am more likely to just jump in with coding, whipping up dummy data as needed and learning about hidden dimensions of the problem domain as I go. Not uncommonly there are data categories that would have been difficult to anticipate. When I discover these, I revise the data model and continue on. Often this approach begins with coding up a script to build the database and populate it. That way, on subsequent iterations, I just modify the db-build script, run it, and I'm back in business.

在第一次项目中,我更有可能只是跳入编码,根据需要掀起虚拟数据,并随时了解问题域的隐藏维度。很少有数据类别难以预料。当我发现这些时,我会修改数据模型并继续。通常,这种方法始于编写脚本以构建数据库并填充它。这样,在后续迭代中,我只修改db-build脚本,运行它,然后我重新开始工作。

#16


0  

This is the age old question. The answer, like every CS answer is that it depends. 90% of the applications that you write are just forms over data. In many of these applications, you will have legacy applications with data that you have to port over an go from there. Therefore, whether you like it or not, the Data/Database is a constricting factor and it drives whatever you do. It’s not just a place to store your domain objects, it is your domain, even though that’s not the “right” way to do things.

这是一个古老的问题。答案,就像每个CS答案一样,它取决于它。您编写的应用程序中有90%只是表单而非数据。在许多这些应用程序中,您将拥有遗留应用程序,其中包含您必须从那里移植的数据。因此,无论您是否喜欢,数据/数据库都是一个限制因素,它会驱动您所做的一切。它不仅仅是存储域对象的地方,它也是您的域名,即使这不是“正确”的做事方式。

In most cases, I’ve designed my data model first in a way that takes the existing data and organizes it into the relational model. I then do basic screen design. Then I build my anemic Active Record type business objects to wire them up. This is by no means the best way to design software, but in most cases, it’s the way that things will be done or have been done. In these cases, your business objects really are just containers for data with business logic around them to wire them up to the screens and insure data integrity and screen security. This sucks, but it is what it is.

在大多数情况下,我首先以一种获取现有数据并将其组织到关系模型中的方式设计我的数据模型。然后我做基本的屏幕设计。然后我构建我的贫血Active Record类型业务对象来连接它们。这绝不是设计软件的最佳方式,但在大多数情况下,这是事情将要完成或已经完成的方式。在这些情况下,您的业务对象实际上只是具有业务逻辑的数据的容器,可以将它们连接到屏幕并确保数据完整性和屏幕安全性。这很糟糕,但事实就是如此。

If screen interactions are the most important thing, then maybe designing the screen first and then have you other objects depend on that will be your best bet.

如果屏幕交互是最重要的事情,那么可能首先设计屏幕,然后让你依赖于其他对象,这将是你最好的选择。

If you are lucky enough to have a Greenfield project where the domain is integral in the application and the database is merely a persistence mechanism for your domain objects, then I would develop the domain objects first using Domain Driven Design in a TDD manor and develop the screens and the database around the domain objects. I would love to code like this more often, but you don’t always get the opportunity in most places.

如果你有幸拥有一个Greenfield项目,其中域是应用程序中不可或缺的,而数据库只是域对象的持久性机制,那么我将首先使用TDD庄园中的域驱动设计开发域对象并开发屏幕和域对象周围的数据库。我希望更频繁地编码这样的代码,但是你并不总是在大多数地方获得机会。

Note: Stack Overflow is designed in a Database as the Model way, so it can't be that evil.

注意:Stack Overflow在数据库中被设计为模型方式,所以它不是那么邪恶。