最佳设计业务领域:将模型与逻辑分开? [英] Optimal design business layar: separate model from logic?

查看:117
本文介绍了最佳设计业务领域:将模型与逻辑分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是设计业务逻辑领域的新手,我正在寻找最佳设计.

什么是设计业务逻辑基础的更好方法:
1.将业务逻辑放入业务实体中.
2.具有静态模型,并通过使用适配器执行业务逻辑.

请参见下面的示例.

有什么更好的做法,什么是利弊?任何建议将不胜感激!

设计1

I''m new to designing a business logic layar and I''m searching for the optimal design.

What is a better way for the design of the business logic layar:
1. Put the business logic within the business entities.
2. Have a static model and perform de business logic by making use of adapters.

See the examples below.

What is better to do and what are de pro''s and cons? Any advise would be greatly appreciated!

Design 1

Dim Customer as New Customer(1)

Customer.Load()
Customer.Name = "John"
Customer.Update()



设计2



Design 2

Dim CustomerAdapter As New CustomerAdapter
Dim Customer As New Customer

Customer = CustomerAdapter.GetCustomerByID(1)
Customer.Name = "John"
Customer.Update

推荐答案

设计1很愚蠢.您最终不得不致电load.我喜欢私有构造函数,喜欢通过ID获取或使用带有所需值的构造函数创建新对象的方法,以及喜欢在DB中创建对象的方法,可以通过编辑属性来对其进行更新.
Design 1 is stupid. You end up having to call load, for a start. I like a private constructor, and methods to get by ID or create a new object with a constructor taking the values needed, and the method creating an object in the DB, which can be updated by editing the properties.


这篇关于最佳设计业务领域:将模型与逻辑分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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