Thursday, March 17, 2005

Photography

Photography is my latest craze. I have developed an interest for digital photography ever since I got my Canon A75 a few months ago. Although, this camera doesn’t have SLR like features, it’s good enough for beginners like me to get started on photography. Once I get really good at the art of photography, I hope to buy the Canon Digital Rebel (EOS 300D) or the Nikon 70D or some other Digital SLR….
I have been playing around with Adobe Photoshop for a couple of weeks now. It’s probably the best piece of software that I’ve ever used. The number of tools available is simply mind-boggling. I have never really used GIMP, but I am told that GIMP supports quite a lot of features that Photoshop currently provides. Guess, I’d be experimenting with GIMP sometime soon.
I have uploaded a few shots that I have taken at http://chirdeep.netfirms.com . I have also uploaded a few Photoshop effects that I’ve experimented with. Hope to update it as frequently as possible. Feedback/Criticism is welcome.

Thursday, March 03, 2005

Bad usage of instanceof

If ( Object instanceof ClassA || Object instanceof ClassB){
// do something
}

I have come across such code in many applications. Why would developers write such horrendous code? It clearly beats the whole purpose of polymorphism, doesn’t it?

Consider ClassA, ClassB and ClassC implement an interface (say InterfaceA). Wouldn’t the code look more elegant if we add a method to InterfaceA (say doSomething()), implement the method in ClassA and ClassB and provide a dummy implementation in ClassC. Then, the code would look like

Object.doSomething();

The problem with this approach occurs when there are too many implementations of InterfaceA and only a few of them need to implement the method doSomething(). In such a case we could create an Abstract class (say AbstractClassA) which provides a default implementation of the method doSomething(), and override the method only in those few classes. I really think this would be a more elegant solution.

Having said all that, I fail to understand why the instanceof operator was provided in the first place!! Is it only to promote short term hacks like this??