|
|
|
|
|
by potatosareok
4170 days ago
|
|
For some reason seeing your code really bothers me. Is it normal to ever use private variables in inheritance like that? Say you had toString() in Article class that returned ("%s%" author, title). Now if you create a MutableArticle on it, ma.toString() will return null unless you override toString on it as well (since Articles variables are private and not inherited). I don't code much so I don't know is it normal to see code like that? Also less relevant but Articles constructor should probably be public? |
|
The Article class is unusable as provided due to the private constructor (in fact, the MutableArticle class wouldn't even compile), but private constructors can be useful. I often use private constructors and instead provide public static methods that call the constructors. This practice is often derided, and goes into Java's perception as a verbose, arcane language, but it allows for improving an API without breaking clients built to previous versions, as well as making an API more clear (since we can give the static methods more descriptive names).