Sunday, April 24, 2016

Switch Statement

It shows just one of the operations that might depend on the type of employee.

There are several problems with this function.

First, it's large, and when new employee types are added, it will grow.
Second, it very clearly does more than one thing.
Third, it violates the Single Responsibility Principle (SRP) because there is more than one reason for it to change.
Fourth, it violates the Open Closed Principle (OCP) because it must change whenever new types are added.

But possibly the worst problem with this function is that there are an unlimited number of other functions that will have the same structure.
For example we could have:
  • isPayday(Employee e);
  • deliverPay(Employee e, Money pay);

The solution to this problem is to bury the switch statement in the basement of an abstract factory, and never let anyone see it.

The factory will use the switch statement to create appropriate instance of the derivatives of employee, and the various functions, such as calculatePay, isPayday and deliverPay will be dispatched polymorphically through the employee interface.

Friday, April 20, 2012

Android Dynamic Spinner

The spinner object on android development really give me a big headache. First I face the OnItemSelectedListener event handler gets called every time it been set. And then I face the same event handler gets called when a spinner selection is changed programmatically.

Finally I manage to write a dynamic spinner example to work correctly.

Tuesday, March 13, 2012

How do I submit a Chinese characters in Struts?


The Chinese characters "UTF-8" encoding not able to work with the above code. The magic trick is on the "TilesRequestProcessor", change
< controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" / >
to
< controller processorClass="com.fabiolee.struts.tiles.RequestProcessor" / >
in the "struts-config.xml" and add in the below class "RequestProcessor.java".

Then it will work nicely.

Thursday, September 8, 2011

Facebook Page Tab Height Scrollbar

If the body content of a html page to be added as a facebook page tab is longer than the usual facebook page height, we want to remove the vertical scrollbar and show the complete html page, here is a simple solution:

Saturday, March 1, 2008

div height error on IE6

IE6 again, "height.html" is an example code of div height error on IE6.

This code running no problem on IE7 & Firefox, but when it reach IE6, the height change to 20px.

Same case as my previous post, I look for Mr Google again. This time I get some post said:
1) IE6 height will have some white space if image is smaller then 12px, we need to set line-height to 0px.
2) IE6 height will have some white space if image is smaller then 20px, we need to set line-height to 0px & set a smaller font-size.

So, my code end up like "height_ie6_fix.html".

Finally, it work perfectly on IE6, IE7 & Firefox browsers.

Monday, February 25, 2008

padding + height problem on Firefox

I though I was facing an error on Firefox browser when using padding & height attributes together in a CSS class. But I was error, in the end, it is still IE browser problem.

Let take an example "height_without_doctype.html"

When we run this code, it will display different output on Firefox & IE.

Firefox height = padding-top + height = 50px + 50px = 100px

IE height = height = 50px

After I find Mr Google, it point me to this url which is perfectly solve my above problem.

The solution is simple, just add in a DOC type, then IE will follow a common standard same as Firefox.

So, the code changed to "height_with_doctype.html"

Both browsers work the same now.

Friday, February 22, 2008

Javascript Menu Navigation

Recently I research on how to implement a javascript menu navigation. At the beginning, I was thinking of use library to make one. But there are so many different request coming in until I decided to develop my own javascript menu navigation.

Here is the sample code that I write (3 levels menu navigation):

During testing on this sample code, I find out that IE6 having some different behavior then IE7 & Firefox on onmouseout() function. If possible, avoid to use that function.