So, Singleton or Monostate?


Continuing with the design pattern fun, lets talk about one of the most commonly used pattern, Singleton and an alternative called Monostate. I too wrote about singleton pattern relative to Joshua Bloch’s Effective Java a few days back. The Basic Difference in Two Well what is this monostate we talk about? Monostate is very similar to a singleton and you may call it a conceptual singleton. The basic difference between the two is that- Problem with Singleton – The intent ...

HttpClient and Web Sniffers


Introduction When I say HttpClient, I talk about a package i.e. org.apache.commons.httpclient in commons-httpclient. HttpClient is used for making post and get request to particular URIs. And one can all kinds of things with the response and response headers. A simple example of sending a: What’s strange with HttpClient? By default, a http request sent using HttpClient is not captured by the web sniffers e.g. fiddler. I have no clue why that happens. But that is a pain in the ...
Generics And Parameter Type Hiding

Generics And Parameter Type Hiding


Generics is an essential ingredient for a extensible and crafty design. When used wisely, generics make a programming language look good. Spiderman has reminded us repeatedly that with great power comes great responsibility. With all the extensibility we might toss the whole point type safety if generics are not used carefully. The following is a discussion about a warning often encountered. Problem Statement : Lets think of a scenario where the issue could be reproduced. Think of a zoo which has ...
Validation API for Complex and Multiple Validations

Validation API for Complex and Multiple Validations


I designed a very simple validation API when I was learning about Builder Pattern. Now, I have improved the code and used it in a small project. The code is now- Generic Can return return objects Has support for compound validators Other improvements have been made; like readability and updating comments Please find the code @ https://github.com/73ddy/poc_trunk/tree/V0.1 Here is a gist of the code, in order to make it sound less boring. Please have a look, and point out my mistakes ...

Kth maximum element in unsorted collection


Finding the Kth maximum element in an unsorted array doesn’t seem to be a big deal. Because, we know that finding the maximum and if we keep on eliminating the largest element from the array. And this we will take us to the Kth maximum element in an array. But this solution is of order O(n2). Can it be done in linear way? Yes. Well, almost. Have a look at the following method written in Java. Generalizing into an algorithm ...