代码之家  ›  专栏  ›  技术社区  ›  Bruno Brant

Separated Presentation on a UI Centric Application

  •  0
  • Bruno Brant  · 技术社区  · 14 年前

    I having trouble figuring out the correct architecture for this kind of application: it's a diagramming application, which resembles MS Visio. The diagrams are used to generated data which is passed to another application.

    When designing applications, I've always tried to used layering, but now I can't decide how to do this when the data is so tightly coupled with the presentation. For example, a certain object in my canvas has a (X,Y) data, which is used for presentation purposes only, but has to be stored like domain data.

    再次感谢!

    更新:

    I'm also aware that 也许吧 在这种情况下,我不应该将UI与域分离。如果是这样的话,请给我一些何时适用分离和何时不适用的理性。

    3 回复  |  直到 14 年前
        1
  •  2
  •   Nir    14 年前

    在图表工具中,形状的X/Y位置是域数据的一部分(形状的位置是图表的一部分-没有它就不能绘制图表),使用这些X/Y坐标并在屏幕上绘制形状的代码是表示层的一部分。

    我知道有些人认为只用于显示的数据应该单独保存,但在我曾经处理过的每个项目中,单独保存的数据都是一个巨大的维护和支持噩梦。

    在一个简单的图表工具中(如果工具只是绘制和编辑图表,而没有基于图表进行任何花哨的处理),没有业务逻辑,只有绘制和编辑图表的代码(属于表示层)和图表数据(即域模型)。

    If there is no business logic, by using a separate set of objects for domain and presentation you'll have to duplicate all your model data twice (once in the model objects and once in the presentation objects) and you won't get any advantages from separating the business logic from the presentation (because there isn't any).

    另一方面,如果您确实有一些对数据运行的算法,那么通过将图形数据与绘图代码分离,您确实可以获得一些东西——您可以在工具之外运行算法,您可以有更好的自动化测试等。

    另外,如果编写另一个对相同数据进行操作的系统,则至少可以共享模型定义,如果将其与图形代码分开,则可以保存/加载代码。

    So, let's summarize:

    • All the diagram data is part of the model (including data only used for presentation purposes).

    • Anything that draws to the screen or handles user input is in the presentation tier (obviously).

    • 如果这两个覆盖了所有的代码和数据而不是应用程序,则没有任何“业务逻辑”,层分离可能是多余的。

    • 如果你有任何代码不适合这两个类别,你认为它应该是模型的一部分,而不是你应该构建两个单独的层。

    • 如果有机会在系统之间共享代码,您应该确保共享的代码不会与表示代码混合在一起。

    • And one last "bonus" point - if this is a project that's likely to be in active development for a long time with new features added in the future - you may want to separate the UI/data anyway just to make future work easier - you have to decide if this future saving is worth the extra time now and if this separation is really likely to help in the future.

        2
  •  1
  •   Joeri Sebrechts    14 年前

    I think you need to make sure you're keeping the what and the how separate. What you are displaying is abstract, sets of coordinates, shape types. How you're displaying it is very specific. I'd make sure the domain model dealt purely with the what and the view layer dealt uniquely with the how. It's hard to get into specifics though without knowing more about your app.

        3
  •  0
  •   Tobias Reithmeier    14 年前

    Maybe this helps a bit,