Showing posts from 2015

Parallel Universes

This story is written by Etgar Keret, an Israel writers.

Image: Getty Images
"There’s a theory that says there are billions of other universes, parallel to the one we live in, and that each of them is slightly different. There are ones where you were never born, and the ones where you wouldn’t want to be born. There are some parallel universes where I’m having sex with a horse, and ones where I win the lottery. There are universes where I’m lying on the bedroom floor, slowly bleeding to death, and universes I’ve been elected president, by a landslide. But I don’t care about those parallel universes now. The only ones that interest me are the ones where she isn’t happily married, with a cute little boy, the ones where she’s completely alone. There are plenty of universes like that, I’m sure. I’m trying to think about them now. Among all those universes there are some where we’ve never met. I don’t care about those now. Among the ones that are left, there are some where she doesn’t…

Breaking the Singleton Design Pattern

A little more about reflection: Another post in my blog
More about singleton: Wikipedia: Singleton pattern

This semester, I have taken part in a course in Master program at HCMUT. Recently, the lecturer is disappointed because the number of students attending the class is so low. So I went to class this morning.

The lecture was about design patterns. At the moment I entered the room, the lecturer demonstrated Singleton patterns and the content was quite simple. When he said that the constructor of the class must be non public so that the outside world wouldn't be able to instantiate a new instance of that class, the first thing came into my mind: REFLECTION. What if there is a man in the outside world, try attacking the principle of singleton by reflection.

The lecturer prefers C# and by chance, I am working with that language, so I will use it as the language of all code in this entry. Also, in this entry, I will play 2 roles: the man trying attacking singleton pattern and the ma…