在newcp的开发过程中,经过权衡后最终使用基于YII框架开发。在使用了YII框架的MVC结构,程序结构自然而然使用了Controller->Model->View。在Model细分层次结构为Service->Logic->ARModel。在这样的结构下,无论是使用JAVA还是.NET的项目,往往容易被套在事务脚本形式,newcp也不例外。每个功能处理都是使用同一个流程。
最后在编写代码的时候,则会出现如下的代码结构(为了便于阅读代码都已经过调整):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| //检查余额 $accountService = new FundsAccountService(); $account = $accountService->checkBalance($orderDetails->customer_id, $orderDetails->amount); if($account == false) { //…… } //产品接口操作 $busiductService = new BusiductService(); $busiduct = $busiductService->getBusiduct($order->busiduct_id); $productOrder = OrderFactory::createOrderInstance($busiduct->product_code); $productOrder->service($orderDetails->orderduct_name, $orderDetails->action); //更新订单状态--已操作 $this->updateStatus($id, BusinessOrder::STATUS_SERVICED); //扣款操作 $financeTypeService = new FinanceTypeService(); $form = new FundsDetailForm(); $form->customer_id = $orderDetails->customer_id; $form->amount = $orderDetails->amount; $form->finance_type_id = $financeTypeService->getTypeByBusiness($orderDetails->busiduct_id, $orderDetails->action); $form->cheque_number = $orderDetails->id; $form->effective_date = new CDbExpression('now()'); $form->note = $orderDetails->orderduct_name; if(false == $accountService->deduct($form)) { //…… } //更新订单状态-已支付 $this->updateStatus($id, BusinessOrder::STATUS_PAID); //更新产品数据信息 $context = $this->getContext($orderDetails); $productOrder->complete($orderDetails->orderduct_name, $context); //更新订单状态--已入库 $this->updateStatus($id, BusinessOrder::STATUS_STORED); //更新订单状态--已完成 $this->updateStatus($id, BusinessOrder::STATUS_FINISHED);
|
事务脚本优势在于简单,但对于复杂业务则冗余代码,并且复用性可扩展性很低。对于复杂的业务必须使用领域模型来替代。实际表现的代码应该如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| //检查余额 $account = new Account($orderDetails->customer_id); if(false == $account->checkBalence($orderDetails->amount)) { //…… } //产品接口操作 $busiduct = new Busiduct($order->busiduct_id); $busiduct->service($order); //扣款操作 if(false == $account->deduct($orderDetails)) { //…… } //更新产品数据信息 $busiduct->complete($order);
|
这中表现形式很直观,便于阅读,并且少了很多updateStatus操作。其实这些updateStatus操作是封装于service、complete等接口中。
这里只是一个简单的例子,实际设计过程中,领域网往往相对比较复杂。领域模型需要一些面向对象技术,以及对领域逻辑相对比较清晰,并且要利用一些架构模式或设计模式。
领域模式如果设计不好则会导致对象过于臃肿,并且降低程序的响应速度。
注:
事务脚本:将所有逻辑组织成单个过程,在过程中直接调用数据库,或者只通过简单的数据库封装器。
领域模型:创建了一张由互联对象组成的网,其中的每一个对象都代表某个有意义的个体(实际对象)。
分类:默认分类 | 1次阅读 |没有评论 |
返回顶部
过程狂热
过程狂热曾在上课时被计算机教师批评,因为这种方法没有使用更加抽象的实现方式。而支持PHP面向过程者的观点“它可以工作!”并不能提高其编程水平和档次。毕业后他们可能找到一个工作,写驱动程序,文件系统或其它的偏向底层的编程,他们的注意力集中于速度和代码的精炼。
“过程狂热”极端的例子是抵制对象,抵制抽象化。他们总在想着如何让程序运行起来更快,而不在乎别人是否能读懂他们的代码。他们常常把编程当成竞赛而不是团队活动。除了PHP外,他们最喜爱的编程语言是C和汇编。在PHP世界中他们可能会开发PECL模块,贡献出高效率的代码。
对象狂热
对象狂热者热衷于在任何时候使用PHP面向对象的风格来书写代码。他们没有真正考虑过用这种方式是否会影响程序的执行效率。有时候让人觉得他们更享受抽象的设计概念而不是现实的代码。他们通常很可能是项目管理者或文档书写者。
对象狂热者指出,如果没有抽象的设计方法我们仍然在使用0和1进行编程。他们喜欢用伪码来描述问题。极端的例子是对象狂热者即使知道有时候会牺牲效率仍然使用对象。除了PHP,他们最喜欢的语言是Java和Smalltalk。在PHP世界中,他们可能会开发PEAR模块,贡献文档化非常好,易于维护的代码。
分类:默认分类 | 187次阅读 |没有评论 |
返回顶部
ESQL/C is an SQL application programming interface (API) that enables you to embed Structured Query Language (SQL) statements directly into a C program. The ESQL/C preprocessor, which the esql command calls, converts each SQL statement and all Informix-specific code to C.
To access a database server through an ESQL/C application
1. Write embedded SQL statements and calls to ESQL/C library functions into your C code to create an ESQL/C program.
2. Convert the ESQL/C program to a C executable file with the esql command.
Compiling an ESQL/C Program: You type the esql command to compile your ESQL/C program. The esql command passes your ESQL/C source file to the ESQL/C preprocessor and to the C compiler. It passes along options that are specific to both the ESQL/C preprocessor and the C compiler to preprocess, compile, and link your ESQL/Cprogram.
The esql command follows these steps to carry out the conversion:
* In Stage 1, the ESQL/C preprocessor performs the following steps:
o Incorporates header files into the source file when it processes all include directives ($include and EXEC SQL include statements)
o Creates or removes compile-time definitions when it processes all define ($define and EXEC SQL define) and undef ($undef and EXEC SQL undef) directives
o In Stage 2, the ESQL/C preprocessor processes any conditional compilation directives (ifdef, ifndef, else, elif, endif) and translates embedded SQL statements to ESQL/C function calls and special data structures.
Stages 1 and 2 mirror the preprocessor and compiler stages of the C compiler. Successful completion of the preprocessing step yields a C source file (.c extension).
Default Compilation Order
ESQL/C source program -> ESQL/C preprocessor -> C source program with SQL statements and ESQL/C calls -> C language preprocessor and compiler -> Executable program
分类:默认分类 | 150次阅读 |没有评论 |
返回顶部
Lighttpd和Nginx都属于轻量级的Web服务器,它们的出现自然会抢占一些属于Apache的市场份额。不过 Lighttpd、Nginx和Apache并不是相互排斥,相互对立的。Lighttpd和Nginx的长处在于处理静态页面,它们的处理速度可以达到 Apache的2~3倍,极端情况下能达到10倍。因此通常情况下,Apache用来作为后台服务器,处理PHP、CGI等,生成动态内容;Nginx用来作为前端服务器,从而充分利用它占用资源少的优势来处理静态页面的大量请求,而Lighttpd则通常用于图片服务器。
分类:架构 | 203次阅读 |没有评论 |
返回顶部