语言和开发规则: Difference between revisions

Jump to navigation Jump to search
Line 557: Line 557:
*'''表模块'''
*'''表模块'''


This is a mix between 2 previous where we have only one unique class for each table of database.
介于前两种方法之间的中间方法,其中每个数据库表都只有一个类实例。


-> As shown in code skeletons (see previous chapter), Dolibarr uses concept of '''Table Module'''.
-> 如代码框架所示(见前面章节),Dolibarr基于 '''表模块''' 的原理设计。


===业务逻辑之间的通信 - data (ORM)===
===业务逻辑 - 数据之间的交互 (ORM)===


There are 3 ways to make links:
有三种交互模式:


*The '''Table And Row Data Gateway'''
*'''表和行 Data Gateway'''


This is the most simple. You have one class per table and each class is a link to the table with CRUD methods (Ceate, Read, Update, Delete). A class instance is a record in the table. The class contains only code to reach lines and fields of table.
这是最简单的方法。我们为每个表创建一个类,每个类都是到相应表的桥梁,并在该表上提供CRUD方法(Ceate, Read, Update, Delete)。其次,类的实例是表的记录。类仅包含表行或列的访问代码。最后,必须将业务代码添加到其他类中。这些表类和业务类之间的链接关系必须是已知的,或可从开发人员的知识中推断出来的。


Example: This mode is used by some ORM Frameworks, like '''iBatis'''.
示例:此模式由某些ORM框架使用,如 '''iBatis'''(http://ibatis.apache.org/<nowiki/>)。


*The '''Active Record'''
*'''Active Record'''


Same as previous, but we are allowed to add some business functions into the class, if such functions are dedicated to the table or recording into this table.
与前一个相同,但允许在类上添加一些业务函数,前提是这些函数非常特定于表或记录所承载的业务概念。这是提供最佳 ''功能/复杂性'' 比的模式。


Example: This mode is used for Dolibarr development and most PHP softwares that include their own framework and best practices.
示例:这是Dolibarr和许多其他PHP应用程序开发的首选模式,这些应用程序有自己的框架和开发实践。


*The '''Data Mapper'''
*'''数据 Mapper'''


Classes represent entities of the problem and not the data. So you have to double, triple ... these classes with Mapper classes to access the data.
类表示问题的实体,而不是数据。所以您必须两次,三次 ... 地调用 '''Mapper''' 类访问数据。这种模式在理论上更“纯粹”,因为它更接近业务,但也有非常复杂和难以在现实中维护的缺点(观察到的实践经验不符合理论的承诺)。
More "purist" on paper (closer of business), this method also has the disadvantage of being more complex in practice.


Example: This is the choice if you use the ORM Framework '''Propel'''. We find this model in heavier applications, based on this ORM among others.
示例:这是 ORM 框架 '''Propel''' 的选择(http://propel.phpdb.org/trac/<nowiki/>)。因此,它可以在基于此ORM的大量的应用程序中找到。


-> For Dolibarr development, it is recommended to use the connection mode '''Active Record''', which offers the advantages of a model close to the business without having the complexity, without obfuscating technical architecture. It is by this way that the development, understanding of code and technical maintenance and / or business behaviour seems the more productive (this is however an ongoing debate between the purists and the pragmatists, debate in which nobody can really be right, because it depends on the objectives).
-> 对于Dolibarr开发,建议使用 '''Active Record''' 链接模式,该模式提供了接近业务模型的优点,而不具有复杂性,也不过度隐藏技术。正是在这种模式下,开发、代码理解以及技术和/或功能维护似乎最有成效(然而,这是纯粹主义者和实用主义者之间的一场永恒的辩论,没有人真正正确,因为一切都取决于要实现的目标)。
714

edits

Navigation menu