如何已被写入在外观模式的签名? [英] How has to be written the signature in facade pattern?

查看:157
本文介绍了如何已被写入在外观模式的签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我定义有揭露一些功能的外观。我的目的是从业务逻辑中分离出presentation层和Web服务层。只有说出它,这是门面模式定义:

I'm defining a facade that has to expose some functionalities. My purpose is to decouple presentation layer and Web Services layer from business logic. Only to state it, this is facade pattern definition:

提供一个统一的接口子系统中的一组接口。外观定义了一个更高层次的接口,使子系统更容易使用

Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use

我有这种疑惑:


  1. 在写一个方法,一个门面,我在他们的参数的复杂性总是怀疑过。我认为,语言的原始参数列表的方法一长串难以阅读和不方便,但很清楚有信息要给予它。在另一方面,我觉得用DTO的效果会更好,因为它们比更接近原始的方法对企业的概念,但程序员不容易知道哪些参数对DTO已被填补......哪种方法你认为更好,为什么?

  1. When writing a method for a facade, I've always in doubt about their parameter's complexities. I think that a long list of language primitive parameter list in a method is difficult to read and unhandy but very clear about the information that has to be given to it. On the other hand, I think that using DTO's would be better because they are nearer than primitive methods to the business concepts, but programmers do not know easily which parameters on the DTO have to be filled... which approach do you consider better and why?

我用三个类型的异常:业务异常(用于业务规则等...),确认异常和系统异常。如何应该是他们传递倒掉时具有兼顾消费者的性质(例如Web服务,presentation层等)的门面消费者?

I'm using three kinds of exceptions: businesses exceptions (used for business rules and so...), Validation Exceptions and system Exceptions. How should be them passed when throwed to the facade consumers having into account the consumer nature (e.g. web service, presentation layer etc.)?.

谢谢!

Pd积:请编写C夏普或Java的例子

P.D.: Please write your examples in C Sharp or Java

推荐答案

这是上面的例子真的好吗?我的意思是:

Is it really ok in an example above? I mean:

PersonDto findPersonByName(String name) { ... }

假设我们使用JPA,有一堆的实体,其中一个是人。
这只是一个普通的POJO,只是标注了一些JPA法宝。
是不是真的有必要写PersonDTO(假设它是一种人镜子),只是为了摆脱JPA注解?如果我的目标是回到人的信息我会简单地返回Person实例。
如果我想返回更多的信息,例如特定的人,它的轮廓,并在服务层等数据计算,我想创建像类:

Let's say we use JPA, have bunch of entities, and one of them is Person. It is just a regular POJO, just annotated with some JPA magic. Is it really necessary to write PersonDTO (assuming it is kind of Person mirror) just to get rid of JPA annotations? If my goal is to return Person information I'd return Person instance simply. If I'd like to return more info, e.g. given person, it's profile, and other data computed in service layer, I'd create class like:

public PersonInfo {
Person p;
PersonProfile;
... additional attributes required by contract...
 }

这篇关于如何已被写入在外观模式的签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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