Friday, 20 June 2008

Simple, embedded, OO Database

No I am not talking about Derby or any other sql DB. I am talking about a real Object oriented DB which makes it easier to implement Domain Driven Development.

DB4O is a open source object database for both Java and .net. DB4O stores data in flat files which is not much different than serilization but the strenth lies within the easy of use. DB4O is very easy to set up and use. Even the test drive tutorial is quite enough for learning how to use. So sad that there is no support for JPA. I think if db4o can offer JPA support it will be a great choise for development phases.

I tested db4o for storing and reading mass amount of data and the results were good. Files sizes don't grow fast and the system can handle object relations well. I also prepared an abstract class which can takeover the persistance job from the domain objects and hides away that complexity. I would really love to try and see what can db4o offer in a real project and production environment.

Countdown to Ganymede

Days of Europa is numbered now, soon we will all be upgrading to Ganymede and looking for new versions of plugins.
Latest version of eclipse, named Ganymede (the largest moon of Jupiter and also the solar system) will be available on 25th of June.
During our presentation on eclipsist in late april, we had chance to review release candidate of Ganymede and had been informed about the new features which were very interesting although this is not a major release.

Welcome Ganymede, and goodbye Europa, you have been so helpful and last year i didn't spend a day without you...

Monday, 9 June 2008

This time last year...

Well as a recent member of 30s club I decided to compare few things with last year. This time last year I was just starting a new project and a new colleague was insisting on using wicket. We have just finished the JSF projects so everybody in the team was quite familiar with that technology. I was personally very interested in Flex which was version 2 by that time.
That time Wicket has just been moved to Apache and in incubating period.
By that time last year my impressions about JSF, Wicket and Flex were;

2007
JSF is outdated, we must leave it behind and evolve. Ajax and Javascript sucks. I am very keen on trying any technology which will replace Javascript. Meanwhile Netbeans offering nice tools for JSF but i can't even imagine replacing Eclipse. GWT can be a nice alternative.
Wicket is nice, you code and debug in native java platform. The Java and Html code is totaly seperated but still not easy to make a designer and developer work seperately. The learning curve is not so easy eventough it is just plain java code. Although wicket has embedded Javascript features, you still need to code javascript which caused our project not to run on firefox in just the begining of the development. Since wicket is under apache now i think their future is bright.
Flex is fantastic but for a year I have been waiting them to make a leap which they couldn't. I am so afraid that developers are so afraid to leave html behind and work in the flash runtime. News about Flex 3 is everywhere. I believe learning curve is very easy and since Flex builder is just a plugin for Eclipse, it feels so comfortable to code.

2008
JSF is still popular Developers are so experienced about JSF. Sun is making a god progress and version 2 early access is available. My toughts about JSF is changed a lot. I believe it is still a good choice since people are so experienced and JSF and its tools become so mature. New vesion of Netbeansagain offering nice features but still i can't imagine to migrate to Netbeans from Eclipse. We are all waiting for weblets. Several application servers are now JavaEE 5 compatible which indirectly makes JSF stronger. Well my new project will be on JSF, I will miss Flex a lot but corporations still prefer JSF.
Wicket is a disappoinment. One year passed and i don't see any progress, I haven't seen any big projects developed over Wicket and people are concerned about future of wicket. My ex-collagues (all are flex developers) who are joining to my old project doesn't want to lern and use wicket. After flex developers don't find wicket fun, the output is plain, javascript is still on the stage and JSF is much mature and developers are more experinced on it.
Flex is version 3 for over 4 months which was not a major release but still very fun to use. Licence prices of the builder dropped. BlazeDS which is a subset of LiveServices is now open sourced. We had completed 2 successful projects with Flex and the one which is (70% wicket, rest flex) still struggling. The team is quite experinced with Flex now and Flex at last made the leap i was expecting long ago. Version 4 news hits on blogs and the new features are amazing. Everything is really on the way on flex side.

Well when I look back I see my views changed so dramatically so I am not sure what will this year bring. Last month we had a presentation and workshop on Flex with Java backend in which everything went so smooth and we could finish a project from strach. Well next week I will be in caves of JSF again so now I am watching the news of JSF 2.0 with more caution.

As i said before by today now I am officially a member of 30s club, am i considered to be a wise and aged programmer? :)

Sunday, 8 June 2008

Design Patterns Revisited (3)- The Façade Pattern, Hiding the complexity of the complex..

It is arguable that the Façade pattern is a design pattern or not but it is sure that it is a nice tool method for software developers. The definition of Façade pattern according to mighty GOF is 
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.
Seems easy isn't it, well façade is act as a gateway for a series of complex procedures you need to do. All you have to do is delegate everything to your façade and use it as a gateway. You need to call a specific method in the complex system, well they are still available, just call them whenever you need. 

One of the most challenging thing people face when they move to away from their families is to do the washing up. Even you own a washing machine, there are many options, procedures and steps you need to complete. So what if we just design a new washing machine with preset programs like for "very dirty clothes; use double amount detergent, get water twice, wash for longer time then dry..etc" or for "very light dirt; use half amount detergent, get water once, wash for shorter, no need to dry..." or just a normal program like "get the detergent, get the water, wash, dry..". None of the steps above makes sense for me and i really don't care what does the machine is doing as long as the output is clean clothes.  So lets just code a class which will be the façade of our washing machine and will only use the methods which were already provided with the washing machine.

    public class Clothes{
         private int amount;
         private String owner;
         private String status;
         ...
    }
    public class WashingPresets {
        private WashingMachine washingMachine=new WashingMachine;
        public Clothes lightWash(Clothes clothes) {
             washingMachine.getWater(50);
             washingMachine.getDetergent(20);
             washingMachine.wash(clothes);
             return clothes;
        }
        public Clothes heavyWash (Clothes clothes){
             washingMachine.getWater(100);
             washingMachine.getDetergent(35);
             washingMachine.wash(clothes);
             washingMachine.getWater(100);
             washingMachine.getDetergent(40);
             washingMachine.wash(clothes);
             washingMachine.dry(clothes);
             return clothes;             
        }
        public Clothes normalWash(Clothes clothes) {
             washingMachine.getWater(100);
             washingMachine.getDetergent(40);
             washingMachine.wash(clothes);
             washingMachine.dry(clothes);
             return clothes;
        }
    }
 
    public class Client{
         // anyone who wants to use our washing machine can just use such a simple code piece
         public void washMyClothes(){
               Clothes clothes=new Clothes();
               WashingPresets ws=new WashingPresets();
               ws.heavyWash(clothes);
         }
    }

We have just used the special methods provided by our tech-end washing machine and hide the complexity in our façade class. So from now on our house mates just need to select the program which suites their laundry. So nice, so easy and so fast but what if one of our house mate is very ungenerous on spending money and doesn't want to use our heavy washing program because it uses to much detergent. Actually all he wants is to rinse the clothes ones more without detergent and with less water and since he is the only want making the trouble we don't want to add this style as a method in our class. So we let him use our façade along with the methods provided by the producer;

    public class TroublesomeClient{
         public void washMyClothes(){
               Clothes clothes=new Clothes();
               WashingPresets ws=new WashingPresets();
               WashingMachine washingMachine=new WashingMachine;
               ws.lightWash(clothes); //façade call
               washingMachine.getWater(50); //native methods call
               washingMachine.wash(clothes); //native methods call
         }
    }

Well we didn't do too much but with this design we can hide the complexity and all clients including the ungenerous one is quite happy since everyone has much less thing to do and it is hard to miss a step and ruin the laundry. 
As mentioned in Head First Design Patterns just try to obey the principle of least knowledge;
Talk only to your immediate friends!
Always hide the complexity from the code which doesn't need to know the details.