Archive for the ‘Design Patterns’ Category

Flot: jQuery Charting Engine

Monday, February 23rd, 2009

For those who know me, I tend to dislike plugins such as flash as it requires user installation and often times does not work well or at all on handheld devices.  Anyways, one of the spots that flash has worked well is real nice interactive graphs.  The only other suitable solution was using server-side generated images with crazy javascript to re-download images on the fly.  I have always been interested in other approaches, and I came across a neat little jQuery plugin named Flot.  Flot is a pure javascript implementation that provides an API to really create stunning and interactive graphs.  It uses Canvas on modern browsers (Firefox, Safari, Chrome, Opera, etc) and excanvas emulator on Internet Explorer.  The transitions are smooth and appealing.  Plus, you leverage all of the power of jQuery, which is my new preferred javascript library of choice.  On a recent project, I used Flot to create a primary graph with an overview graph beneath it.  The overview graph was similar to Google Finance graphs in providing a full view of the graph.  The primary graph then allowed zooming in.  Above the graph was a jQuery slider that allowed scrolling the graph once zoomed in.  The total effort to build this was just a few hours and literally less than a 100 lines of code.  The simplicity and power of Flot is truly amazing and I highly recommend checking it out in your next projects.

For more examples and screenshots, check out the actual Flot examples.

End IE6 Support on Aug 27 Campaign

Thursday, February 19th, 2009

Microsoft Internet Explorer v6 has long been a crippling effect to web developers worldwide.  It’s slow development pace, lack of continuous updates, shortcomings in web standards, and usage of proprietary standards (ie: ActiveX) all cause developers continued headaches.  Rather than support the new web standards such as CSS 2.1 and CSS 3, HTML5, etc, developers must create workarounds.  This results in less usability, more development time, and maintenance nightmares.  If the internet is to ever see Web 3.0, we must bring IE6 support to an end.  Only then, can developers create all types of interactive and exciting content, creating a new flourishing of content.  For the positive side of life, Internet Explorer v8 is much better in terms of standards and support, although it is still far behind other browsers such as Firefox, Opera, etc.

There are only two ways to cause IE6 to cease to exist:  (1) convince all IE6 users to upgrade (2) force all users to upgrade.  In January 2009, the estimated market share of IE6 was 19% (Browser Market Share).  Unfortunately, that is too many users to either convince or just abandon.  However, we can start warning (ie: forcing) users to upgrade over a time period and once that time period has elapsed, sites immediately stop supporting IE6 and require users to upgrade to view content.  Sometimes the only way to get users to do something is to proactively suggest and eventually force them into it.

That being said, I am beginning the push to start displaying warnings to users that IE6 will be deprecated and no longer supported on August 27, 2009.  Why August 27, do you ask?  Per Wikipedia, IE6 was originally released on Aug 27, 2001.  That means that on Aug 27, 2009, 8 years will have passed.  That is more like 20-30 years in the digital technology age and plenty of time for users to have upgraded to a new version of IE or better yet another browser.

I am calling all web developers to join me in helping to bring IE6 to its final resting place in history.  As a suggestion, here are some examples for how to go about this.

  • Use IE6 javascript detection and on page load show a modal dialog telling the user they are using an older browser that will cause certain features to not work and provide a list of links to other browsers, including IE8
  • Provide an advertisement on the page that informs users that their browser needs to be updated to view improved content on the site
  • Provide a warning at the top of the page informing the user to upgrade with a list of links

Also, mention to the user that on August 27, 2009 their browser will no longer be supported.  If we can get sites to implement this, then maybe we can start causing the market share to quickly drop and eventually deteriorate by its birthday on August 27.

Note that I am not alone in this fight.  See the following:

J2EE Project Structures

Wednesday, February 18th, 2009

I have always been a huge proponent for separation of concerns, code reusability, and code independence such that you can easily move code around, replace, re-use, etc.  Even though often times you sacrifice speed due to additional layers of indirection, you gain much in maintainability.  Maintainability is often an overlooked statistic as it is harder to measure than just time.  However, as versions are released, use cases evolve, and technology stacks change, that maintenance nightmare can start to build quickly.  Well balanced project structures can endure very well over time, far more than quickly thrown together projects.  Even though a quick thrown together project can be shipped sooner, in the end it will fail to release version updates as fast and will result in a higher lifecycle cost (due to bugs, maintenance issues, etc).  Anyways, enough with the project management side.  What I really wanted to share was my ideal project structure that I am proposing to myself to use for future projects.
(more…)

Controlling GC and Improving Unit Testing through Factories

Monday, October 13th, 2008

So I was looking at design patterns and read across the factory pattern and the pooling pattern. I know what both of those do independently but never considered them together and as a result, my mind started racing with ideas. One of the many problems with applications in terms of performance is garbage collection. Pooling helps to solve this problem by reusing objects that have been released back to the pool. One of the big problems with unit testing is testing classes in pure isolation by properly injecting mock objects that are dependencies of the class under test. IoC helps to resolve this issue by injecting code into classes. However, you still have to at times use ‘new’ to create objects. This causes three big issues. First, the VM has to create a new object, initialize it, and add it to the stack. This is an expensive task. Second, you put dependency into the code. Further, if you utilize pooling you add yet another dependency (think coupling here). Third, using new does not allow you to truly run code in isolation as your class under test is not invoking code on another object without being able to use a mock instance.

So, how can you solve these problems, you ask, and what do they have to do with factory and pooling design patterns? Well, let’s go back to my initial remark on the factory and pooling design patterns. First, we will talk about the factory design pattern. A factory design pattern is simply a class that loads or creates other classes. That is exactly what we want to do. Further, this allows us to do a few things. First, it abstracts how an object is created and lets you add custom handling to any type of object by simply using a different factory. This helps to reduce other less performance-based solutions such as AOP or adapters and wrappers. Second, it removes the usage of the new operator so that you can easily mock the class under test in pure isolation by registering mock objects with the factory. Third, it promotes loose coupling by not having classes worry about pooling, initialization, etc. POJOs only depend on the Factory as a simple static object. With that said, let’s look at some examples to further clarify.

(more…)