Simon recently found himself working alongside a "very senior" developer- who had a whopping 5 years of experience. This developer was also aggrieved that in recent years, Object Oriented programming had developed a bad reputation. "Functional this, functional that, people really just don't understand how clean and clear objects make your code."
For example, here are a few Java objects which they wrote to power a web scraping tool:
class UrlHolder {
private String url;
public UrlHolder(String url) {
this.url = url;
}
}
class UrlDownloader {
private UrlHolder url;
public String downloadPage;
public UrlDownLoader(String url) {
this.url = new UrlHolder(Url);
}
}
class UrlLinkExtractor {
private UrlDownloader url;
public UrlLinkExtractor(UrlDownloader url) {
this.url = url;
}
public String[] extract() {
String page = Url.downloadPage;
...
}
}
UrlHolder
is just a wrapper around string, but also makes that string private and provides no accessors. Anything shoved into an instance of that may as well be thrown into oblivion.
UrlDownloader
wraps a UrlHolder
, again, as a private member with no accessors. It also has a random public string called downloadPage
.
UrlLinkExtractor
wraps a UrlDownloader
, and at least UrlLinkExtractor
has a function- which presumably downloads the page. It uses UrlDownloader#downloadPage
- the public string property. It doesn't use the UrlHolder
, because of course it couldn't. The entire goal of this code is to pass a string to the extract
function.
I guess I don't understand object oriented programming. I thought I did, but after reading this code, I don't.