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

Intermediate tour: Classes chapter #4564

Open
wants to merge 2 commits into
base: intermediate-tour-staging
Choose a base branch
from

Conversation

sarahhaggarty
Copy link
Collaborator

This PR is to add the second chapter of the intermediate tour to the staging branch.

Copy link
Contributor

@danil-pavlov danil-pavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge work, maybe the most the useful content on the website
My only concern again is the size of these chapters

I think It could be three pages, for example

  1. Classes and interfaces 2. Objects 3. Open and other special classes
    the 3rd page could be even a part of the Advanced tour

abstract class Animal
```

To declare a function **without** an implementation, you also use the `abstract` keyword:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's too detailed (after all, it's an intermediate tour) and can be shortened to

To declare a function or a property without implementation, you also use the abstract keyword:

with one code example for both

to define different product categories:

```kotlin
abstract class Product( val name: String, var price: Double ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and in the code blocks below, spaces are unnecessary around the class properties inside the brackets

Although abstract classes are great for sharing code in this way, they are restricted by the fact that classes in Kotlin
only support single inheritance. If you need to inherit from multiple sources, consider using interfaces.

For more information about abstract classes, see [Abstract classes](classes.md#abstract-classes).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more information about abstract classes, see [Abstract classes](classes.md#abstract-classes).
For more information, see [Abstract classes](classes.md#abstract-classes).

In the example:

* `PaymentMethod` is an interface that has an `initiatePayment()` function without an implementation.
* `PaymentType` is an interface that has a `paymentType` property that isn't initialized.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `PaymentType` is an interface that has a `paymentType` property that isn't initialized.
* `PaymentType` is an interface that has the `paymentType` property that isn't initialized.


In the example:

* `PaymentMethod` is an interface that has an `initiatePayment()` function without an implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `PaymentMethod` is an interface that has an `initiatePayment()` function without an implementation.
* `PaymentMethod` is an interface that has the `initiatePayment()` function without an implementation.


Enum classes can have properties and member functions just like normal classes.

For example, let's say that you are working with HTML and you want to create an enum class that contains some colors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example, let's say that you are working with HTML and you want to create an enum class that contains some colors.
For example, let's say you're working with HTML and want to create an enum class containing some colors.

In this example, the `containsRed()` member function accesses the value of the enum constant's `rgb` property using the
`this` keyword, and checks if the hexadecimal value contains `FF` as its first bits to return a boolean value.

For more information about enum classes, see [Enum classes](enum-classes.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For more information about enum classes, see [Enum classes](enum-classes.md).
For more information, see [Enum classes](enum-classes.md).

```

In this example, the `containsRed()` member function accesses the value of the enum constant's `rgb` property using the
`this` keyword, and checks if the hexadecimal value contains `FF` as its first bits to return a boolean value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`this` keyword, and checks if the hexadecimal value contains `FF` as its first bits to return a boolean value.
`this` keyword and checks if the hexadecimal value contains `FF` as its first bits to return a boolean value.

### Inline value classes

Sometimes in your code, you may want to create small objects from classes and use them only briefly. This approach can
have a performance impact. Inline value classes are a special type of class that avoid this performance impact. However,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
have a performance impact. Inline value classes are a special type of class that avoid this performance impact. However,
have a performance impact. Inline value classes are a special type of class that avoids this performance impact. However,

* Creates an instance of the `Email` class called `email`.
* Calls the `sendEmail()` function on the `email` object.

By using an inline value class, the class is inlined and used directly in your code without creating an object. This can
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
By using an inline value class, the class is inlined and used directly in your code without creating an object. This can
By using an inline value class, you make the class inlined and can use it directly in your code without creating an object. This can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants