Reading through a scathing article on the downsides of OOP in favour of some other paradigm I've run into an example that I can't find too much fault with.
I want to be open to the author's arguments, and although I can theoretically understand their points, one example in particular I'm having a hard time trying to imagine how it would be better implemented in, say, a FP language.
// Consider the case where “SimpleProductManager” is a child of // “ProductManager”: public class SimpleProductManager implements ProductManager { private List products; public List getProducts() { return products; } public void increasePrice(int percentage) { if (products != null) { for (Product product : products) { double newPrice = product.getPrice().doubleValue() * (100 + percentage)/100; product.setPrice(newPrice); } } } public void setProducts(List products) { this.products = products; } } // There are 3 behaviors here: getProducts() increasePrice() setProducts() // Is there any rational reason why these 3 behaviors should be linked to // the fact that in my data hierarchy I want “SimpleProductManager” to be // a child of “ProductManager”? I can not think of any. I do not want the // behavior of my code linked together with my definition of my data-type // hierarchy, and yet in OOP I have no choice: all methods must go inside // of a class, and the class declaration is also where I declare my // data-type hierarchy: public class SimpleProductManager implements ProductManager // This is a disaster. Note that I am not looking for a rebuttal for or against the writer's arguments for "Is there any any rational reason why these 3 behaviours should be linked to the data hierarchy?".
What I'm specifically asking is how would this example be modelled/programmed in a FP language (Actual code, not theoretically)?