Database communication in modular software?

杀马特。学长 韩版系。学妹 提交于 2020-06-18 09:50:24

问题


I'm building web app that has modular design.

I have ER database schema for whole app. Tables there are grouped by the module they will be used by. There will be core modules and I plan to add new ones that depend on that core i.e. that need data from core modules tables.

When NEW module needs to access core tables, what practices should I follow:

1.In purpose of reading,

  • a. is it okay to read from core tables or I need to build interfaces in core module?
  • b. is JOIN operation with core tables good practice?

2.In purpose of writing,

  • a. I know that only good practice is using core module interfaces.

回答1:


You should have a data access layer (DAL) in your application design that abstracts the database. The only module that should know about the physical database is the DAL. All other modules should get their data from the DAL.

So

  • 1a. Do not read from tables. Use an interface (DAL) for reading and writing. Modules should not need to know where the data is coming from.
  • 1b. There is nothing wrong with using joins. Joins are a fundamental aspect of SQL.



回答2:


It depends.

You get better modularity if you don't access core tables from other modules. But you also get less performance, especially if you don't use joins.

I'm normally not dogmatic about not accessing tables across modules, if there isn't a specific requirement making it necessary. Like databases for modules being separate or not existing when modules aren't installed.



来源:https://stackoverflow.com/questions/8539617/database-communication-in-modular-software

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!