From String Builder – The Daily WTF

Inheritance is one of those object-oriented concepts that creates a lot of conflict. You’ll hear people argue about what constitutes an “is-is” vs “has-is” relationship, you’ll hear “they prefer composition over inheritance”, you’ll see languages ​​adopt mixing patterns that use inheritance for composition. If used well, the feature can make your code cleaner to read and easier to maintain. If used badly, it’s a way to get your polymorphism on the side of spaghetti code.

Greg was working on the front end of a medical data application. This representative line shows how they use inheritance:

  public class Patient extends JavascriptStringBuilder

Greg writes, “Unfortunately, the designers weren’t familiar with emerging ideas like separating the object model from the UI layer, so they gave us this gem.”

This, of course, was the usual pattern in the front end of the application. Many data objects inherited from array constructors. Not all them, which only added to the additional confusion.

Regarding why? Well, it gave those objects a “string” function, which they could override to generate output. Want to print the patient on the screen? What could be easier than calling patient.string()?

[Advertisement]

ProGet has you covered with security and access controls for your NuGet feeds. Find out more.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *