逻辑,设计和数据的分离 [英] Separation of logic, design and data

查看:74
本文介绍了逻辑,设计和数据的分离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,编码员,同工奴隶,借给我我的耳朵。


我相信在一个完美的世界里设计一个网站(或功能)
在网站上)应该与它的设计完全分开,并且它提供的数据是b $ b。我想要一些好方法的建议,

,因为在现实世界中它可能非常困难。


例如,如果我我在MySQL数据库中翻找,表格结构和生成SQL请求的代码通常是相互关联的。重组您的表格,您必须相应地更新您的

代码。


另一个更严重的问题是设计与代码的分离。对于

示例,如果我使用表格将我的页面划分为单独的块'

(例如顶栏,菜单,内容部分,侧面)吧,横幅空间,

等)然后这些表格和表格单元格的结构是与程序流程相关的
:你设置一个表格或表格

cell,做一些将数据输出到那个单元格的东西,关闭单元格

和/或表格,然后转到下一个单元格做其他事情。br />
删除或添加单元格意味着应该或不应该调用向该单元格输出数据的函数。或者

中执行代码的顺序可能会受到影响:如果我想要一个页面范围的顶部

条形单元格,后面跟着菜单栏和下面的内容窗口,我

需要首先渲染顶部条形表行,跨越两列,然后

启动一个新的表行,我将放置菜单和内容单元格。但是

如果我想要一个菜单​​栏一直到屏幕顶部和一个顶部

条形单元格后跟一个内容单元格都在右边的

菜单栏,我需要首先渲染菜单单元格,跨越两行,

然后进行渲染顶部栏和内容单元格。


当然可以将抽象和模块化带到极端的b $ b级别(例如将每行与表相关的代码放入单独的

模板文件中并包含这取决于程序流程)但是这个很快就增加了复杂性和开销,超出了可接受的b / b
。更不用说理想情况下不应该从内容模板文件中发出

函数调用。


那么真正的开发人员如何做到这一点呢? />

问候,

Frank

Friend, coders, fellow wage slaves, lend my your ears.

I believe that in a perfect world the design of a website (or feature
on a website) should be totally separated from its design and the data
it serves up. I''d like some suggestions on good ways to do this,
because in the real world it can be quite difficult.

For example, if I''m rummaging around in a MySQL database, the table
structure and the code that generates the SQL requests are often
interrelated. Restructure your table(s) and you have to update your
code accordingly.

Another, more serious issue is the separation of design from code. For
example, if I''m using tables to divide my pages into separate ''blocks''
(e.g. for a top bar, menu, content section, side bar, banner space,
etc.) then the structure of these tables and table cells are
interrelated with the program''s flow: you set up a table or table
cell, do something that outputs data into that cell, close the cell
and/or table, and move on to the next cell to do something else there.
Removing or adding a cell will mean that the function(s) that output
data into that cell should or should not be called. Or the order in
which code is executed could be affected: if I want a page-wide top
bar cell followed by a menu column and a content window underneath, I
need to render the top bar table row first, spanning two columns, then
start a new table row in which I''d put the menu and content cell. But
if I want a menu bar all the way to the top of the screen and a top
bar cell followed by a content cell both to the right hand side of the
menu column, I need to render the menu cell first, spanning two rows,
and then progress to rendering the top bar and content cells.

One could of course take abstraction and modularization to extreme
levels (e.g. put every line of table-related code into a separate
template file and include that depending on program flow) but this
quickly increased both complexity and overhead to beyond what is
acceptable. Not to mention the fact that ideally one should not issue
function calls from within a content template file.

So how do real developers do this?

Regards,
Frank

推荐答案

Frank van Wensveen写道:
Frank van Wensveen wrote:

我相信在完美的世界中,网站的设计(或网站上的功能

)应该与其设计和数据完全分开

它可以提供服务。我想要一些好方法的建议,

因为在现实世界中它可能非常困难。
I believe that in a perfect world the design of a website (or feature
on a website) should be totally separated from its design and the data
it serves up. I''d like some suggestions on good ways to do this,
because in the real world it can be quite difficult.



将样式与其余部分分开是smiple(原文如此):使用CSS执行所有

布局,配色方案等。


之后你仍然遇到这样一个问题,即你的代码必须按照正确的顺序输出页面 - 比如
,输出HTML

首先是头部的东西,然后是身体的东西,然后是侧边栏的东西,并用

完成一些legalese和footer的东西。这可以使用模板

引擎来解决。有几个可用,但我不能说我喜欢它们中的任何一个,我通常使用粘贴的界面编写我自己的模板引擎

以下。 (事实上​​,我最近才把它编码为一个合适的PHP接口,

之前我使用过一个标准类,我会扩展一两个方法

of。


此界面允许您使用(注意看似随机的顺序):

Keeping styling separate from the rest is smiple (sic): just do all your
layout, colour schemes, etc with CSS.

After that you''ve still got the problem of the fact that your code has to
do things in the correct order to output the page -- say, output HTML
header stuff first, then body stuff, then sidebar stuff, and finish with
some legalese and footer stuff. This can be solved using a template
engine. There are several available, though I can''t say I like any of
them, I generally write my own template engine using the interface pasted
below. (Infact, I''ve only recently coded it as a proper PHP Interface,
earlier I used a standard class, which I would extend one or two methods
of.

This interface allows you to use (note the seemingly random order):


t = new StdTemplate( ''Foo Bar'');
t = new StdTemplate(''Foo Bar'');


t-> add_section(''Foo'',''< p> Foo< / p>'',' 'foo'',

StdTemplate :: DIVISION_MAIN,2);
t->add_section(''Foo'', ''<p>Foo</p>'', ''foo'',
StdTemplate::DIVISION_MAIN, 2);


这篇关于逻辑,设计和数据的分离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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