Koders Search - search codes here!

Tuesday, April 04, 2006

Composite Pattern

I am on a mission of diving deep into the world of Object Oriented Design.It's not that i havent done OOD, it's just that these days due to lack of manpower and tight dateline i had to sacrifice a lot on designing my application upfront.So i began to loose touch on my basics.Now coding straightaway is my design.Well at least i got the applications running on production.And i just found that Composite Pattern is cool like a cup of hot nescafe in the morning!I never cross path with Composite Pattern..not until I was read Professional Java JDK 5 Edition and came across the Design Pattern chapter that discussed Composite Pattern. In my two years stint with Java i used few design patterns like DAO pattern, Service Locator Pattern and Strategy Pattern but not Composite Pattern. Composite Pattern proves useful when you are dealing with Collections. It provides a way for developers to process Collections of objects as a single object which makes operation on the Collection less complicated. I tried developing my own sample for displaying my company organization tree structure. I found that using this pattern leads to a very clean and readable code and not to mention it hides the complexity of recursivley looping through the Collections. I just wish that we did this during our HR System project but that was 2 years ago and i was not even a Java Developer back then. But i guess it's better late than never..just added another weapon in my programming arsenal..heh!

No comments: