Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor English fixes #329

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions basics/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

D provides support for classes and interfaces like in Java or C++.

Any `class` type inherits from [`Object`](https://dlang.org/phobos/object.html) implicitly.
All `class` types implicitly inherit from [`Object`](https://dlang.org/phobos/object.html).

class Foo { } // inherits from Object
class Bar : Foo { } // Bar is a Foo too
Expand All @@ -22,28 +22,30 @@ when no references to an object exist anymore.
### Inheritance

If a member function of a base class is overridden, the keyword
`override` must be used to indicate that. This prevents unintentional
`override` must be used. This prevents unintentional
overriding of functions.

class Bar : Foo {
override functionFromFoo() {}
}

In D, classes can only inherit from one class.
In D, each class may only directly inherit from one other class.
This prevents the diamond inheritance problem, and isn't a limitation
in practice because D (like Java), supports interfaces.

### Final and abstract member functions

- A function can be marked `final` in a base class to disallow overriding
it
it.
- A function can be declared as `abstract` to force derived classes to override
it
it.
- A whole class can be declared as `abstract` to make sure
that it isn't instantiated
- `super(..)` can be used to explicitly call the base constructor
that it isn't instantiated.
- `super(..)` can be used to explicitly call the base constructor.

### Checking for identity

For class objects, the `==` and `!=` operators compare the contents of the objects.
For class objects, the `==` and `!=` operators compare the _contents_ of the objects.
Therefore, comparing against `null` is invalid, as `null` has no contents.
The `is` compares for identity. To compare for nonidentity, use `e1 !is e2`.

Expand Down