本文介绍了EJB 有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习 Java-EE,拥有丰富的 C++ 经验并学习了 Java SE.我不明白 Enterprise Java Beans 的目的;有人可以为我澄清这一点.我对遗留用途不感兴趣:这是在 EJB-3.1 和 Java-EE 6 的上下文中.

I'm currently learning Jave-EE, having plenty of C++ experience and having learned Java SE. I don't understand the purpose of Enterprise Java Beans; can someone clarify this for me. I'm not interested in legacy uses: this is in the context of EJB-3.1 and Java-EE 6.

似乎有人用它们来包含业务逻辑,用于实现常规3层架构的业务层.这将域逻辑与域对象分开,导致贫血域模型.但这违背了我所有的 OOD 直觉;我同意 Martin Fowler 的观点,这是一种反模式.我应该放松对贫血领域模型的反对吗?或者 EJB 有其他用途吗?

It seems that some people use them to contain the business logic, for implementing the business layer of the conventional 3-layer architecture. That separates the domain logic from the domain objects, leading to an anemic domain model. But that goes against all my OOD instincts; I agree with Martin Fowler that it is an anti-pattern. Should I relax my objections to an anemic domain model? Or do EJBs have other uses?

推荐答案

Java EE 的使用并不自动意味着一个贫乏的域模型,就像你可以在说 java 中编写代码一样,没有充分利用最佳实践的东西不会'这意味着它在 Java 中是不可能的.我相信 Martin Fowler 的观点是 J2EE(注意使用 J2EE 而不是 Java EE)几乎强制执行逻辑和数据操作.使用基于 POJO 的实体允许对数据和行为进行适当的建模.EJB 中的业务逻辑"通常会编排业务逻辑的应用程序,但通常并不实际执行它,它通常是一个非常薄的包装器.

Use of Java EE does not automatically imply a anemic domain model, just as you can write code in say java what does not make good use of best practices doesn't mean it's not possible in java. I believe Martin Fowler's point was J2EE (note the use of J2EE and not Java EE) pretty much enforced operation of logic and data. Using POJO based entities allows data and behaviour to modelled appropriately. The "business logic" in your EJBs typically orchestrates application of business logic but more often than not does not actually perform it, it is usually a very thin wrapper.

EJB 因此形成了您的服务 API,无论您使用的是哪个平台/框架,您都需要它,您需要有一些可以物理调用的东西,它是一个入口点.无论您是使用 spring、Web 服务等实现...您都需要一个服务层,Java EE 中已经实现了这一点.一个相当人为的例子

EJBs thus form your Service API, you need this whichever platform/framework you are using, you need to have something you can physically invoke, it is an entry point. Whether you are implementing using spring, web services etc... You need a service layer, there is nothing stopping this been implemented in Java EE. A rather contrived example

@Stateless
public SomeServiceImpl implements SomeService
    someServiceMethod() {
       delegate.doSomething();
    }
}

public SomeServiceDelegate implements SomeService
    someServiceMethod() {
       modelObject.doSomething();
    }
}

我不打算讨论比任何其他技术更喜欢 EJB 的原因,只是想指出使用它们并不意味着您的实现不能使用最佳实践.

I'm not going into the reasons to prefer EJBs over any other technology, just wanting to point out that using them doesn't mean your implementation can't use best practice.

这篇关于EJB 有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:56