improve: expand strings intro and rewrite inheritance concept docs#3115
improve: expand strings intro and rewrite inheritance concept docs#3115bull1210 wants to merge 1 commit intoexercism:mainfrom
Conversation
strings/introduction.md was only 13 lines with no examples of actual String methods. Expanded it to cover common methods, immutability, equals() vs ==, StringBuilder, and String.format. inheritance/introduction.md had a semantically wrong example (Lion.bark), awkward phrasing, a link to javatpoint instead of Oracle docs, and no mention of super or abstract classes. Full rewrite with a clean example and proper coverage. inheritance/about.md had invalid Java syntax: 'interface Animal()' — interfaces don't have parentheses. Fixed the interface declaration and updated the method name to match the introduction. Co-Authored-By: bull1210 <bull1210@gmail.com>
| @Override | ||
| public void bark() { | ||
| System.out.println("Lion here!!"); | ||
| public void makeSound() { |
There was a problem hiding this comment.
Is it worth having an example of a child using something from the parent? The introduction opened by saying we can reuse fields and methods, but the first example looks like we're rewriting (by overriding) makeSound.
| Consider a class, `Animal` as shown, | ||
| Inheritance lets one class build on top of another, reusing its fields and methods without rewriting them. | ||
| The class being extended is called the **parent** (or superclass); the class doing the extending is the **child** (or subclass). | ||
| The relationship is described as IS-A: a `Dog` IS-A `Animal`. |
There was a problem hiding this comment.
Suggest explicitly stating that Dog is extending Animal to make it really explicit and clear:
| The relationship is described as IS-A: a `Dog` IS-A `Animal`. | |
| The relationship is described as IS-A. For example, if `Dog` class extends an `Animal` class, the relationship can be described as a `Dog` IS-A `Animal`. |
| ``` | ||
|
|
||
| ## Abstract classes | ||
|
|
There was a problem hiding this comment.
I think Abstract classes is a bit out of place in the inheritance introduction and would probably be better in class's about instead or a separate concept that comes after both inheritance and classes concepts (of the two, I favor as a separate concept).
|
|
||
| ## Building strings dynamically | ||
|
|
||
| When you need to construct a string piece by piece (e.g. inside a loop), use `StringBuilder` instead of concatenating with `+`. |
There was a problem hiding this comment.
Using + hasn't been introduced and there doesn't seem to be an example. I'd suggest adding one.
| To read more about inheritance in Java, see the [official documentation][java-inheritance]. | ||
|
|
||
| [java-inheritance]: https://www.javatpoint.com/inheritance-in-java#:~:text=On%20the%20basis%20of%20class,will%20learn%20about%20interfaces%20later. | ||
| [java-inheritance]: https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html |
There was a problem hiding this comment.
I'd suggest using Dev.java where possible. The top of Oracle page states that Dev.java has the latest stuff. The Dev.java page for inheritance is at For inheritance, the page is at https://dev.java/learn/inheritance/.
Quality improvements to two concept docs that had real problems.
strings/introduction.md
The existing file was 13 lines and only mentioned that strings exist and "have methods". Expanded it to cover the most commonly used String methods with examples, explain immutability properly, show why
.equals()matters over==, and introduceStringBuilderandString.formatfor building strings dynamically.inheritance/introduction.md
Rewrote this one from scratch. The old version had a few issues:
bark()on a parentAnimalclass — semantically odd since lions don't barksuperor abstract classes at allThe rewrite uses a proper
makeSound()method, introducessuperwith a real example, covers abstract classes, and links to the official Java tutorial.inheritance/about.md
Fixed a syntax error in the interface example:
interface Animal()— interfaces don't have()after the name. Changed tointerface Animaland updated the method signature tomakeSound()to match the introduction.