Wednesday, June 30, 2010

Using Model-View-Controller differently - to isolate volatile parts of your application

Even if your application does not have a GUI, you can benefit from MVC.
I was trying to write automated tests using JUnit/Cactus and it quickly got unmanageable.
Each test case involved creating several business objects, filling each with lots of data, and then invoking on business services. Since there were different combinations of the data, for each test case, one had to create a new class. Ridiculous!
The solution was:
View (interacting with the outside)
This was not a GUI, but simply a JUnit class.
TestCases contains the test methods, and inherits from JUnit’s TestCase. It has a reference to the concrete data set and instantiates the specific data set. TestDataSet0, TestDataSet1…
It invokes on TestDataSet0 to retrieve the BusinessObjects object to perform its testcases.

Model (Volatile part)
Interface TestDataSet has getter methods
BusinessObjects getBOCombination1()
BusinessObjects getBOCombination2()…
Concrete class TestDataSet0,1,2… implements this interface.
It has a reference to class BusinessObjects.
The data can be filled from the database, or simply hardcoded.

Class BusinessObjects contains methods to populate each Business Object.
populateBO1(), populateBO2()

So each time there is a different combination of data, create a class TestDataSet_N - yes, it is another class but all it is concerned with is the hardcoding of data, or retrieving of that data combination from the database.

The advantage of this design is, it allows reuse of methods, isolates the hard-coded data (that keeps changing from case to case) and enables more rapid progress.

Monday, June 21, 2010

What Next Android?

Just my 2 cents. Google will do its own thing regardless of all the
developers hanging from the Android train - our financial wellbeing is not its concern.

It seems to me that Google is yet to figure out, "What Next?".
Someone on the newsgroups said that Android and Chrome were built because Google didn't want to be shut out from the advertising platforms like Nokia, iPhone. I think they correctly saw it as a futuristic platform and wanted control of mobile platforms, just like M$ did on PCs. So they built this thing called Android and now that they control it, are not quite sure how to profit from it. It is just another mobile operating system with an app store, like Palm, iPhone, Nokia.

Can you write an app on Android that couldn't have been written on the
other OS'es? Does a user with an Android phone have a better day than
those with no-name phones? Good Advertising seduces us to perceive in
a new light what is 'cool' and that acquiring it will also make us