Search This Blog

Posts

If you use Spring framework for more than a week you are probably aware of this feature. Suppose you have more than one bean implementing a given interface. Trying to autowire just one bean of such interface is doomed to fail because Spring has no idea which particular instance you need. You can work around that by using @Primary annotation to designate exactly one "most important" implementation that will have priority over others. But there are many legitimate use cases where you want to inject all beans implementing said interface. For example you have multiple validators that all need to be executed prior to business logic or several algorithm implementations that you want to exercise at the same time. Auto-discovering all implementations at runtime is a fantastic illustration of Open/closed principle: you can easily add new behavior to business logic (validators, algorithms, strategies - open for extension) without touching the business logic itself (closed for modific…

TL;DR: I did a computer simulation of behavior evolution of monkeys, continue reading to see how problem was stated originally in The Selfish Gene. First part shows my Java implementation, second part shows charted results and conclusions.

The problem
I read The Selfish Gene by Richard Dawkins recently, very wide-opening book despite being 40 years old. While the original text is sometimes outdated ("you could pack only a few hundred transistors into a skull - more like trillions these days, hello Moore's law) general claims are as appealing as they used to.

One chapter that especially grabbed my attention, as a computer engineer, was about animals performing social grooming, like some species of monkeys (see picture above). Let me quote relevant chapter:

Suppose a species [...] is parasitized by a particularly nasty kind of tick which carries a dangerous disease. It is very important that these ticks should be removed as soon as possible. [...] An individual may not be abl…