singleton or non-singleton

来源:互联网 发布:js获取地址栏链接 编辑:程序博客网 时间:2024/05/22 05:28

http://martinfowler.com/articles/injection.html

 

1.

Components and Services

I use component to mean a glob of software that's intended tobe used, without change, by application that is out of the control ofthe writers of the component. By 'without change' I mean that theusing application doesn't change the source code of the components,although they may alter the component's behavior by extending it inways allowed by the component writers.

A service is similar to a component in that it's used byforeign applications. The main difference is that I expect a componentto be used locally (think jar file, assembly, dll, or a sourceimport). A service will be used remotely through some remoteinterface, either synchronous or asynchronous (eg web service,messaging system, RPC, or socket.)

 

2.Beans are defined to be deployed in one of two modes: singleton or non-singleton. (The latter is also called a
prototype, although the term is used loosely as it doesn't quite fit). When a bean is a singleton, only one shared
instance of the bean will be managed and all requests for beans with an id or ids matching that bean definition
will result in that one specific bean instance being returned.
The non-singleton, prototype mode of a bean deployment results in the creation of a new bean instance every
time a request for that specific bean is done. This is ideal for situations where for example each user needs an
independent user object or something similar.

Beans are deployed in singleton mode by default, unless you specify otherwise.

 

 

原创粉丝点击