Five ‘s Weblog

October 23, 2007

POJO Facade

Filed under: Five's thought — by powerdream5 @ 9:23 pm
Tags: , ,

      The day before yesterday, I made a brief introduction to the Facade pattern. Today, let’s make a little bit advance. Because I am studying lightweight frameworks now, I am pretty willing to share my own knowledge about POJO facade pattern with you!

10_23_1_2007.jpg

      From the name of POJO facade, it is easy to tell that it is based on the facade pattern. The main responsibility of POJO facade is to manage the transaction and database connection. In fact, when we refer to POJO facade, we always like to compare it with Session facade. They have two big differences. The first one is POJO facade donesn’t need the services provided by the EJB Server. Because POJO facade pattern is specific for lightweight framework, such as Spring and Acegi Security, which will provide services to it instead of EJB Server. The second difference is that POJO facade choose to return the domain object to the present layer instead of DTO(Data Transfer object). As we all know, DTO just holds data and not has behaviros. The biggest disadvantage of DTO is that we always need to write a lot repeated and redundant codes to create it.

10_23_2_2007.jpg

      As mentioned above, POJO facade returns domain objects to the present layer instead of DTO. However, this way has one drawback that the present layer may call the mehtods of the domain objects directly instead of through POJO facade, so that these calls will not be executed in transaction. In order to solve this problem, we can combine POJO facade with Adapter pattern. Firstly, we define an interface, which contains all the methods the present layer need access. Then, we should create an adapter which implements this interface. And this adapter will transfer all the requests from the client to the domain objects.

     When we use POJO facade, another problem we need to concern is that how the POJO facade returns the domain objects to the present layer(we call it detach). Because of the problem of open session in view. We have to make sure the domain objects returned by POJO facade are the ones needed by the present layer, and the present layer will not access the other domain objects which have not beed loaded from the database.

10_23_3_2007.jpg

Advertisements

5 Comments »

  1. […] Jay Westerdal wrote an interesting post today onHere’s a quick excerptThe second difference is that POJO facade choose to return the domain object to the present layer instead of DTO(Data Transfer object). As we all know, DTO just holds data and not has behaviros. The biggest disadvantage of DTO is that … […]

    Pingback by domain check » POJO Facade — October 24, 2007 @ 6:10 am |Reply

  2. Good one.

    I got some idea about this from

    http://j2eeworld.weebly.com

    But this is more in detail.

    Comment by scg — July 23, 2008 @ 4:39 am |Reply

  3. That last photo is really darling. I might just copy it.

    Comment by Facade Design — March 13, 2009 @ 2:18 am |Reply

  4. just do clone() method ;]

    Comment by ciapa — May 20, 2009 @ 3:14 am |Reply

  5. just do equal() method if you already have a girl)

    Comment by Lanqu — June 25, 2009 @ 7:46 am |Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: