为服务层设计消息

发布于 2024-09-29 07:30:08 字数 1463 浏览 1 评论 0原文

我即将开发一个小型应用程序,该应用程序应由服务器和富客户端组成。 到目前为止,我将遵循以下设计准则:

  • 永远不要向客户端公开域对象
  • 封装服务消息以响应和请求对象
  • 根据用例识别服务例程,以便它们始终是原子的

我真正的问题(独立于语言)是我不知道要对消息设计(响应和请求对象)做出什么决定。

它们应该基于可重用部分(例如 CustomerDTO 或 CustomerData 等数据对象)还是每个消息都应该是单独的?也许使用嵌套类来获取详细信息和嵌入项目)。

我知道并不是每个用例都需要甚至允许显示或更改所涉及实体的所有属性,因此这导致了一种设计,其中多个消息应该是一组封闭的类。

你有什么建议?

最好的问候,

agent_harris

编辑:

给出更详细的例子。

假设我们有以下接口:

interface CustomerService {

    /**
     * this use-case should return all necessary data to
     * edit a customer record, including the associated 
     * invoice/delivery addresses
     */

    CustomerRecordResponse getUserRecord(int userId);

}

现在的问题是如何以这种方式组成 CustomerRecordResponse,其组件 是可重用的,但不会为其他可能不会的用例透露太多信息 允许访问或更改特定属性。

我的想法之一是引入小班授课,必要时可以扩展。 例如:

class CustomerData {

    private String firstName;
    private String lastName;

    // ...
}

它基本上只是一组属性(平面对象)。 现在,当涉及到自动编辑包含地址选项的完整记录时 可能是将 CustomerData 类(可能在本地作为嵌套类)扩展为:

class CustomerRecordResponse {
    // nested class:
    class ExtendedCustomerData extends CustomerData {
        private AddressCountryData[] addresses;
    }
}

在这里我会看到我可以重用基类型组件来提供的优点 一个已经存在的 UI 小部件,它可能是 UI 组合的一部分。

否则,当设计完全独立的平面消息对象时,所有数据都将是不同的,并且双方都需要大量开销。

然而,我的目标是设计一个在第一阶段明确实现的客户端/服务器应用程序 采用同类技术(.NET Remoting 或 Java RMI),但可以轻松启用 SOAP 支持。

i am about to develop a small application that should consist of a server and a rich client.
so far i will follow the following design guidelines:

  • never expose domain objects to the client
  • encapsulating service messages to response and request objects
  • identify service routines based on use-cases, so that they are always atomic

my real problem (language independent) is that i have no idea what decision to make regarding message design (response and request objects).

should they be based on reusable parts (e.g. data objects like CustomerDTO or CustomerData) or should each message be individual; maybe using nested classes for details and embedded items).

i know that not each use-case will require or even allow all attributes of involved entities to be shown or changed, so that leads to a design where several messages should be an enclosed set of classes.

what would you suggest?

best regards,

agent_harris

EDIT:

to give a more detailed example.

let's say we have the following interface:

interface CustomerService {

    /**
     * this use-case should return all necessary data to
     * edit a customer record, including the associated 
     * invoice/delivery addresses
     */

    CustomerRecordResponse getUserRecord(int userId);

}

now the question is how to compose the CustomerRecordResponse that way, that its components
are reusable but without revealing too much information for other use-cases that may not
allow to access or change specific properties.

one of my thoughts was to introduce small classes that could be extended if necessary.
for example:

class CustomerData {

    private String firstName;
    private String lastName;

    // ...
}

which is basically only a set of attributes (a flat object).
now when it comes to edit atomically a complete record including addresses an option
could be to extend the CustomerData class (maybe locally as nested class) to:

class CustomerRecordResponse {
    // nested class:
    class ExtendedCustomerData extends CustomerData {
        private AddressCountryData[] addresses;
    }
}

here i would see the advantage that i can reuse the base-type components to feed
an already existing UI widget which is maybe part of an UI composition.

otherwise when designing completely separate flat message objects all data would be divergent and a lot of overhead would be necessary - on both sides.

my goal however is to design a client/server app which is in phase 1 definitely implemented
in homogeneous technology (.NET Remoting or Java RMI) but with the possibility to easily enable SOAP support.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘东忘西忘不掉你 2024-10-06 07:30:08

定义两个接口:客户端和服务器,以便协议和通信介质可以变化(例如,这对于仅使用内存缓冲区进行通信单元测试很有用)。
客户端界面可以非常简单( on_message( MESSAGE_ID , NUM_OPS, OPS) );

对于您可以创建或生成的每条消息(请参阅 Google 的协议缓冲区 )一个类。
然后创建从 Message_ID 到消息对象的 MAP。
消息对象将验证消息并执行相关操作。

Define two interfaces: Client and Server, so that the protocol and the medium of communication can vary (this is useful for example to unit test the communication just with an in-memory buffer).
The client interface can be very simple ( on_message( MESSAGE_ID , NUM_OPS, OPS) );

For each message you can create or generate (see Google's protocoll buffers) a class.
Then create a MAP from Message_ID to the Message Object.
The message object will validate the message and execute the relative action.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文