Design pattern: Flyweight

Adam is a cunning lad. He has been double-dating Elina and Carina. However he has identified himself with different names to each of them. Elina knows him as Adrian and Carina knows him as Boris. Is Adam cheating? Well, Adam begs to differ. He says life is short and he is a limited resource, only one person. Why not have fun with two girls at a time? Inside himself, he is always the same Adam. But he switches to two different personalities for the sake of Elina and Carina, by changing his external behaviour. Morally questionable, no doubt. But he is a fine specimen of the flyweight pattern. Continue reading “Design pattern: Flyweight”