分层可重用架构的框架 [英] Frameworks for Layering reusable Architectures

查看:18
本文介绍了分层可重用架构的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,我的目的是用您的回答生成一个存储库,以便在选择用于开发企业通用应用程序的框架时为社区服务.这非常适用于通用语言,例如 C++、C# 或 Java.

My question is very simple, my intention is to generate a repository with your responses so it could serve to the community when selecting frameworks for developing enterprise general purpose applications. This could apply very well for general purpose languages such as C++, C# or Java.

  • 您建议使用什么框架来生成分层架构?
  • 根据您的经验,为什么您更喜欢使用某些框架而不是您自己的架构?
  • 您认为您选择的框架会在软件开发行业中作为首选方案持续多久?

推荐答案

这确实是一个过于笼统的问题,尤其是因为对 framework 这个词有很多解释,而且在世界范围内框架为不同的任务提供了许多不同的类型.尽管如此,我还是会尝试一下 Java.

This is indeed an overly general question, especially since there are so many interpretations of the very word framework, and within the world of frameworks many different kinds for different tasks. Nevertheless, I'll give it a shot for Java.

Java 的默认整体企业框架称为 Java EE.Java EE 非常强调分层架构.这是一个相当大的框架,学习它的各个方面可能需要一些时间.它支持多种类型的应用程序.非常小的和简单的可能只使用带有一些 scriptlet 的 JSP 文件,而较大的可能使用更多.

The default overall enterprise framework of Java is called Java EE. Java EE strongly emphasis a layered architecture. It's a quite large framework and learning every aspect of it can take some time. It supports several types of applications. Extremely small and simple ones may only use JSP files with some scriptlets, while larger ones may use much more.

Java EE 并没有真正强制您使用它的所有部分,而是您可以挑选自己喜欢的.

Java EE doesn't really enforce you to use all parts of it, but you pick and choose what you like.

自上而下由以下部分组成:

Top down it consists of the following parts:

对于 Web 层,Java EE 主要定义了一个组件和基于 MVC 的 Web 框架,称为 JSF - JavaServer Faces.JSF 使用一种基于 XML 的视图描述语言(模板语言),称为 Facelets.页面是通过定义模板并让模板客户端为其提供内容(包括其他小面)并最终在其上放置组件和通用标记来创建的.

For the web layer Java EE primarily defines a component and MVC based Web Framework called JSF - JavaServer Faces. JSF utilizes an XML based view description language (templating language) called Facelets. Pages are created by defining templates and letting template clients provide content for them, including other facelets and finally placing components and general markup on them.

JSF 提供了一个明确定义的生命周期,用于完成每个 Web 应用程序应该做的所有事情:转换请求值、验证它们、调用业务逻辑(模型)并最终委托给(Facelets)视图进行渲染.

JSF provides a well defined life-cyle for doing all the things that every web app should do: converting request values, validating them, calling out to business logic (the model) and finally delegating to a (Facelets) view for rendering.

要获得更详细的描述,请在此处查看 BalusC 的一些文章,例如主要缺点是什么Java Server Faces 2.0?

For a more elaborate description look up some of the articles by BalusC here, e.g. What are the main disadvantages of Java Server Faces 2.0?

Java EE 框架中的业务层由一个轻量级的业务组件框架表示,称为EJB - Enterprise JavaBeans.EJB 应该包含应用程序的纯业务逻辑.EJB 负责处理事务、并发和需要时的远程处理.

The business layer in the Java EE framework is represented by a light-weight business component framework called EJB - Enterprise JavaBeans. EJBs are supposed to contain the pure business logic of an application. Among others EJBs take care of transactions, concurrency and when needed remoting.

通过应用@Stateless 注释,一个普通的Java 类变成了一个EJB.默认情况下,该 bean 的每个方法都是自动事务性的.意思是,如果调用该方法并且没有事务处于活动状态,则启动一个,否则加入一个.如果需要,可以调整甚至禁用此行为.在大多数情况下,事务对程序员是透明的,但如果需要,Java EE 中有一个显式 API 来手动管理它们.这是 JTA API - Java 事务 API.

An ordinary Java class becomes an EJB by applying the @Stateless annotation. By default, every method of that bean is then automatically transactional. Meaning, if the method is called and no transaction is active one is started, otherwise one is joined. If needed this behavior can be tuned or even disabled. In the majority of cases transactions will be transparent to the programmer, but if needed there is an explicit API in Java EE to manage them manually. This is the JTA API - Java Transaction API.

EJB 上的方法可以通过使用@Asynchronous 注释轻松地异步执行.

Methods on an EJB can easily be made to execute asynchronous by using the @Asynchronous annotation.

Java EE 通过专门用于 EJB 的单独模块的概念明确支持分层.这将隔离这些 bean 并防止它们访问它们的更高层.请参阅此 在 JavaEE 6 WAR 与 EAR 中打包 EJB 更详细的解释.

Java EE explicitly supports layering via the concept of a separate module specifically for EJBs. This isolates those beans and prevents them from accessing their higher layer. See this Packaging EJB in JavaEE 6 WAR vs EAR for a more elaborate explanation.

对于持久性,Java EE 框架附带了一个名为 JPA - Java Persistence API 的标准 ORM 框架.这是基于使用@Entity 批注和@Id 对它们的属性或字段进行批注的纯Java 类.可以选择(如果需要)通过关于对象和对象关系如何映射到关系数据库的注释指定更多信息.

For persistence the Java EE framework comes with a standard ORM framework called JPA - Java Persistence API. This is based on annotating plain java classes with the @Entity annotation and a property or field on them with @Id. Optionally (if needed) further information can be specified via annotations on how objects and object relations map to a relational database.

JPA 非常强调纤细的实体.这意味着实体本身是尽可能多的 POJO,可以轻松发送到其他层甚至远程客户端.Java EE 中的实体通常不关心自己的持久性(即它不持有对数据库连接等的任何引用).相反,提供了一个名为 EntityManager 的单独类来处理实体.

JPA heavily emphasizes slim entities. This means the entities themselves are as much as possible POJOs that can be easily send to other layers and even remote clients. An entity in Java EE typically does not take care of its own persistence (i.e. it does not hold any references to DB connections and such). Instead, a separate class called the EntityManager is provided to work with entities.

使用这个 EntityManager 最方便的方法是在 EJB bean 中,这使得获取实例和处理事务变得轻而易举.但是,也支持在任何其他层中使用 JPA,甚至在框架之外(例如在 Java SE 中).

The most convenient way of working with this EntityManager is from within an EJB bean, which makes obtaining an instance and the handling of transactions a breeze. However, using JPA in any other layer, even outside the framework (e.g. in Java SE) is supported as well.

这些是典型企业应用中与传统层相关的最重要的服务,但 Java EE 框架支持大量附加服务.其中一些是:

These are the most important services related to the traditional layers in a typical enterprise app, but the Java EE framework supports a great many additional services. Some of which are:

消息在 Java EE 框架中通过 JMS API - Java 消息服务直接支持.这允许业务代码向所谓的队列和主题发送消息.应用程序的各个部分甚至远程应用程序都可以监听这样的队列或主题.

Messaging is directly supported in the Java EE framework via the JMS API - Java Messaging Service. This allows business code to send messages to so-called queues and topics. Various parts of the application or even remote applications can listen to such a queue or topic.

EJB 组件框架甚至有一种专为消息传递而定制的 bean;消息驱动 bean,它有一个 onMessage 方法,当 bean 正在侦听的队列或主题的新消息传入时,该方法会自动调用.

The EJB component framework even has a type of bean that is specifically tailored for messaging; the message driven bean which has a onMessage method that is automatically invoked when a new message for the queue or topic that the bean is listening to comes in.

在 JMS 旁边,Java EE 还提供了一个 event-bus,它是完整消息传递的简单轻量级替代方案.这是通过 CDI API 提供的,该 API 是一个综合性的 API,其中包括为 Web 层提供范围并处理依赖项注入.作为一个相当新的 API,它目前与 EJB 和 JSF 中所谓的托管 bean 部分重叠.

Next to JMS, Java EE also provides an event-bus, which is a simple light-weight alternative to full blown messaging. This is provided via the CDI API, which is a comprehensive API that among others provides scopes for the web layer and takes care of dependency injections. Being a rather new API it currently partially overlaps with EJB and the so-called managed beans from JSF.

Java EE 提供了许多开箱即用的远程处理选项.EJB 可以暴露给愿意并能够通过二进制协议进行通信的外部代码,只需让它们实现远程接口即可.

Java EE provides a lot of options for remoting out of the box. EJBs can be exposed to external code willing and able to communicate via a binary protocol by merely letting them implement a remote interface.

如果二进制通信不是一种选择,Java EE 还提供了各种 Web 服务实现.这是通过 JAX-WS(Web 服务、soap)和 JAX-RS(Rest)完成的.

If binary communication is not an option, Java EE also provides various web service implementations. This is done via among others JAX-WS (web services, soap) and JAX-RS (Rest).

为了调度周期性或定时作业,Java EE 提供了一个简单的计时器 API.此 API 支持使用自然语言的类似 CRON 的计时器,以及用于延迟执行代码或跟进检查的计时器.

For scheduling periodic or timed jobs, Java EE offers a simple timer API. This API supports CRON-like timers using natural language, as well as timers for delayed execution of code or follow up checks.

Java EE 的这部分是可用的,但正如前面提到的相当基础.

This part of Java EE is usable but as mentioned fairly basic.

Java EE 中还有很多东西,但我认为这涵盖了最重要的东西.

There are quite some more things in Java EE, but I think this about covers the most important things.

Java 的另一种企业框架是 Spring.这是一个专有但完全开源的框架.

An alternative enterprise framework for Java is Spring. This is a proprietary, though fully open source framework.

就像 Java EE 框架一样,Spring 框架包含一个 Web 框架(称为 Spring MVC)、一个业务组件框架(简称 Spring,或 Core Spring Framework)和一个 Web 服务堆栈(称为 Spring Web Services).

Just as the Java EE framework, the Spring framework contains a web framework (called Spring MVC), a business component framework (simply called Spring, or Core Spring Framework) and a web services stack (called Spring Web Services).

尽管 Java EE 框架的许多部分都可以独立使用,但与 Java EE 相比,Spring 更强调构建您自己的堆栈.

Although many parts of the Java EE framework can be used standalone, Spring puts more emphasis on building up your own stack than Java EE does.

Java EE 与 Spring 的选择通常是受宗教影响的.从技术上讲,这两个框架都提供了类似的编程模型和相当数量的功能.Java EE 可能被视为更轻量级(强调约定优于配置)并具有类型安全注入的好处,而 Spring 可能会提供更多开发人员经常需要的较小的便利方法.

The choice of Java EE vs Spring is often a religiously influenced one. Technically both frameworks offer a similar programming model and a comparable amount of features. Java EE may be seen as slightly more light-weight (emphasis convention over configuration) and having the benefit of type-safe injections, while Spring may offer more of those smaller convenience methods that developers often need.

此外,Spring 提供了更彻底和直接可用的安全 API(称为 Spring Security),其中 Java EE 向(第三方)供应商开放了许多安全细节.

Additionally Spring offers a more thoroughly and directly usable security API (called Spring Security), where Java EE leaves a lot of security details open to (third party) vendors.

这篇关于分层可重用架构的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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