Welcome!

Open Source Authors: Elizabeth White, Pat Romanski, Liz McMillan, Roger Strukhoff, Felix Xavier

Related Topics: Java, XML, SOA & WOA, Websphere, Weblogic, Open Source, AJAX & REA

Java: Article

Lessons to Learn from the Hibernate Core Implementation

Hibernate Core is a good example of open source projects to learn from, don't hesitate to take a look inside it.

Hibernate is an open source Java persistence framework project. Perform powerful object relational mapping and query databases using HQL and SQL.

In general the widely used libraries are well designed and implemented, and it's very interesting to learn from them some coding best practices. Let's take a look inside the hibernate core library and discover some of its design keys. In this post Hibernate Core is analyzed by JArchitect to go deep inside its design and implementation.

Package by Feature
Package-by-feature uses packages to reflect the feature set. It places all items related to a single feature (and only that feature) into a single directory/package. This results in packages with high cohesion and high modularity, and with minimal coupling between packages. Items that work closely together are placed next to each other.

Here's a good article talking about packaging by feature.

Hibernate core contains many packages, each one is related to a specific feature hql, sql, and others.

hibernate1

Coupling
Low coupling is desirable because a change in one area of an application will require fewer changes throughout the entire application. In the long run, this could alleviate a lot of time, effort, and cost associated with modifying and adding new features to an application.

Here are three key benefits derived from using interfaces:

  • An interface provides a way to define a contract that promotes reuse. If an object implements an interface then that object is to conform to a standard. An object that uses another object is called a consumer. An interface is a contract between an object and its consumer.
  • An interface also provides a level of abstraction that makes programs easier to understand. Interfaces allow developers to start talking about the general way that code behaves without having to get in to a lot of detailed specifics.
  • An interface enforce low coupling between components, what's make easy to protect the interface consumer from any implementation changes in the classes implementing the interfaces.

Let's search for all interfaces defined by Hibernate Core, for that we use CQLinq to query the code base.

from  t in Types where t.IsInterface select t


More Stories By Lahlali Issam

Lahlali Issam Lead Developer at JavaDepend, a tool to manage and understand complex Java code. With JavaDepend, software quality can be measured using Code Metrics, visualized using Graphs and Treemaps, and queried using CQL language, a SQL like to query the code base.