views:

49

answers:

3

What stands for Factory postfix? Thx.

+3  A: 

Since it's sole responsibility is to create a Session: a factory that produces Sessions.

Andreas Paulsson
+2  A: 

A factory is a design pattern. It is a class that creates objects. The session factory creates sessions.

Stefan Steinegger
+2  A: 

A factory object is one whose sole purpose is creation (instantiation) of other objects. NHibernate uses the SessionFactory to manage the creation of ISessions.

By the same measure - the ProxyFactoryFactory creates a factory that can produce proxies. The larger problem it solves is it allows to keep a level of abstraction in code so that two distinct modules don't need to understand each others' implementation details (i.e. concrete instances) in order to work together.

If we had to create a new NHibernate SessionImpl when we wanted to open a session, we'd need to be able to supply all of its dependencies in a local scope. Here's the code out of the SessionFactoryImpl in NHibernate that actually creates a session:

        SessionImpl session = new SessionImpl(connection, this, autoClose, timestamp, sessionLocalInterceptor ?? interceptor,
                                              settings.DefaultEntityMode, settings.IsFlushBeforeCompletionEnabled,
                                              settings.IsAutoCloseSessionEnabled, settings.ConnectionReleaseMode);

I'd much rather just use

sessionFactory.OpenSession();

than have to manage all of those dependencies ;)

Kevin McKelvin