首页 \ 问答 \ 应用程序外观模式的最佳实践(Best practice for application facade pattern)

应用程序外观模式的最佳实践(Best practice for application facade pattern)

我有一个多层SOA应用程序和一个包含100多个表的数据库。 我正在为我的数据层使用实体框架来处理所有CRUD操作。

我有一个门面类,它托管在一个服务上,可以通过全部客户端应用程序调用。

这个facade类包含诸如的方法

private void DoSomething()
{
  //insert to table1
  //insert to table 2
  //delete from table 3
  //more CRUD operations
}

而且Facade类基本上已经充满了类似于DoSomething()的其他方法。

因此,客户端基本上将创建Facade类的实例,并获得对所有这些方法的访问权限。

我现在的问题是,这是门面图案的最佳做法吗? 我觉得门面类太“重”了,如果我的应用程序扩展得更大,我不确定它是否会影响性能。

如果我有大量的方法,那么创建一个facade类的实例是一个非常昂贵的操作吗?


I have a multi tiered SOA application and a database with over 100 tables. I'm using entity framework for my data layer which takes care of all CRUD operations.

I have 1 facade class which is hosted on a service, callable by client apps all over.

This facade class contains methods such as

private void DoSomething()
{
  //insert to table1
  //insert to table 2
  //delete from table 3
  //more CRUD operations
}

And the facade class is basically full with loads of other methods similar to DoSomething()

So the client will basically create an instance of the facade class, and gain access to all these methods.

My question now is, is this the best practice for a facade pattern? I feel that the facade class is way too "heavy" and I'm not sure if it will affect the performance if my application scales bigger.

Will creating an instance of the facade class be a very expensive operation if I have loads of methods in it?


原文:https://stackoverflow.com/questions/12738819
更新时间:2022-02-24 11:02

最满意答案

您可以查看Mongoose 虚拟机 ,这些虚拟机是您可以获取和设置但不会持久保存到数据库的属性:

Game.schema.virtual('won').get(function() {
  return this.result === 'Won'
})

http://mongoosejs.com/docs/guide.html#virtuals

如果您只想在模板中使用它,那么您还可以在视图中的本地人身上设置特定属性。

也许是这样的:

...

exports = module.exports = function(req, res) {

  var view = new keystone.View(req, res)

  var locals = res.locals

  locals.games = []

  view.on('init', function(next) {

    var query = {} // Add query here

    Game.model.find(query).exec(function(err, games) {

      // Handle error

      games.forEach(function(game) {
        game.won = game.result === 'Won'
      })

      locals.games = games

    })

  })

}

...

You could look at Mongoose virtuals which are properties that you can get and set but that do not get persisted to the database:

Game.schema.virtual('won').get(function() {
  return this.result === 'Won'
})

http://mongoosejs.com/docs/guide.html#virtuals

If you just want to use it in your template then you could also set a specific property on locals in your view.

Perhaps something like this:

...

exports = module.exports = function(req, res) {

  var view = new keystone.View(req, res)

  var locals = res.locals

  locals.games = []

  view.on('init', function(next) {

    var query = {} // Add query here

    Game.model.find(query).exec(function(err, games) {

      // Handle error

      games.forEach(function(game) {
        game.won = game.result === 'Won'
      })

      locals.games = games

    })

  })

}

...

相关问答

更多
  • 事实证明我对view.query的原始更改是正确的。 我只需要重新启动我的数据库。 Turns out that my original change with view.query was correct. I just needed to restart my database.
  • 这是错误消息的重要部分: Mongo Error: [Error: failed to connect to [localhost:27017]] Keystone无法连接到您的数据库,您也可以通过在终端中运行以下命令来确认: mongo localhost:27017 很难说出具体原因,但您应该查看相关文档以在OS X上安装MongoDB Community Edition 。 This is the important part of the error message: Mongo Error: ...
  • Keystone使用port设置,该设置回退到process.env.PORT , process.env.OPENSHIFT_NODEJS_PORT ,最终返回3000 。 您可以通过多种方式更改此设置,方法是在keystone.js文件中设置port ,如下所示: keystone.init({ name: 'My App', brand: 'My App', port: 3010 //... }); 要么 keystone.set('port', 3010); 或者 ...
  • 修复此问题,确保所有节点模块都在服务器上,使用sourcetree保持超时推送到repo,因此模块不在那里。 我代替他们FTP了。 Fixed this by making sure all node modules were on the server, pushing to the repo using sourcetree kept timing out, so the modules weren't there. I FTP'd them instead.
  • 注释掉的代码声明了keystone_user类型的资源 ,而不是类。 据推测,它的类型keystone_user由puppet-keystone模块提供。 include()系列函数用于声明类,而不是资源,因此它们不适用于keystone_user 。 您可以通过多种方式继续进行。 如果你没有想到比声明一个或多个keystone_user更复杂的东西,那么我建议给你的类一个用户名的参数,你可以通过Hiera为其分配一个值: class kilo2_keystone($usernames = []) { ...
  • 显然keystone无法弄清楚我的网络的代理设置,因此连接到不同的网络修复此问题 apparently keystone could not figure out my network's proxy settings so connecting to a different network fixed this
  • 您可以查看Mongoose 虚拟机 ,这些虚拟机是您可以获取和设置但不会持久保存到数据库的属性: Game.schema.virtual('won').get(function() { return this.result === 'Won' }) http://mongoosejs.com/docs/guide.html#virtuals 如果您只想在模板中使用它,那么您还可以在视图中的本地人身上设置特定属性。 也许是这样的: ... exports = module.exports = func ...
  • 目前,WireCloud仅在使用wirecloud.fiwarelabtheme主题时从IdM服务器注销。 此外,您必须编辑FIWARE_PORTALS设置并覆盖Account门户的定义(并可能删除其他门户)。 我已经创建了一张修复此问题的票 。 这是FIWARE_PORTALS设置的默认值: FIWARE_PORTALS = ( {'name': 'Cloud', 'url': 'https://cloud.lab.fiware.org', "logout_path": "/logout"}, ...
  • 我认为问题与KeystoneJS内部处理Types.Name字段类型的方式有关。 在您的jade文件中,您应该使用其虚拟name.full属性的路径引用您的name字段。 在内部, name.full有一个setter,它将name拆分为name.first和name.last 。 因此,如果您希望为名字和姓氏分别input ,则应使用name.first和name.last 。 如果您想要input单个input的全名,则应使用name.full 。 尝试替换名称字段的input控件: input.for ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)