Skip to content

add classes and methods lesson - #117

Open
zachwaffle4 wants to merge 6 commits into
frcsoftware:mainfrom
zachwaffle4:stage0/classes-methods
Open

add classes and methods lesson#117
zachwaffle4 wants to merge 6 commits into
frcsoftware:mainfrom
zachwaffle4:stage0/classes-methods

Conversation

@zachwaffle4

Copy link
Copy Markdown
Member

Description

I use two example classes here to demonstrate value classes and classes with mutable state.

Part of #16.

Meta

Merge checklist:

@github-actions github-actions Bot added Curriculum material Curriculum materials, lessons for students, etc examples stage0 labels Jul 23, 2026
@github-actions

Copy link
Copy Markdown

🌐 Preview URL: https://pr-117.frcsoftware.pages.dev

@zachwaffle4
zachwaffle4 requested a review from Adrianamm July 23, 2026 01:36
@zachwaffle4 zachwaffle4 moved this to In progress in FRC Software Jul 23, 2026
@samfreund
samfreund force-pushed the stage0/classes-methods branch from 6a9a47c to 6576c3c Compare July 23, 2026 20:39
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx Outdated
Comment thread examples/stage0/snippets/classes-methods/RobotTracker.java
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx Outdated
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx Outdated

@Daniel1464 Daniel1464 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added some comments here

Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
@zachwaffle4
zachwaffle4 force-pushed the stage0/classes-methods branch from 24d72a4 to 6ebecc0 Compare July 27, 2026 18:12
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx Outdated
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx Outdated
@zachwaffle4
zachwaffle4 force-pushed the stage0/classes-methods branch from 6ebecc0 to cd87076 Compare July 28, 2026 01:50

@Daniel1464 Daniel1464 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the changes! Here's some small nitpicks

Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx
Comment thread src/content/docs/learning-course/stage0/classes-methods.mdx

@Daniel1464 Daniel1464 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Most of the comments are optional except for the one on line 244. (Sorry for not thoroughly reviewing earlier, btw)

This means that they can only be accessed by methods in the same class.

So far, the `x` and `y` fields each belong to a specific `Point` object.
Sometimes, though, we want a value that's shared by every object of a class, instead of one copy per object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know that static members are traditionally described this way, but i personally think that it kind of misses the point. For instance, saying that Math.clamp() is a method that belongs to all objects of Math doesn't really make sense, since you can never create instances of Math anyways.

Personally, I would change it to "static fields are variables that are related to the class, but don't belong to any particular object."

Notice that we used the `final` keyword to make these fields **immutable**.
This means that once they are created, they cannot be changed.
Immutable fields are also called **constant** fields.
A general rule of thumb is to make all fields `final` unless you have a good reason not to,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be changed to "A field is a variable that belongs to instances of this class".

Another thing to add would be "Notice that these fields don't have values assigned to them! That's because the values of x and y are different between every Point object. In later sections, we'll define code that sets the values of these fields."

Then, we're going to add three fields.
A **field** is a variable that belongs to a class, and stores part of an object's state.
Every `Point` object will have its own copy of each field, so two different `Point` objects can have different coordinates.
Firstly, we add two `double` fields, x and y, which represent the point's coordinates.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could add "This means that every Point created will have an x and y attribute" to contrast with static fields.


```

Finally, we're going to define a `norm` method that returns the length of the `Point` object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Saying "the distance of the point from 0,0" instead of "length of the point object" would be slightly clearer.


```

We create new `Point` objects using the `new` keyword followed by the constructor.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this needs to be earlier, probably after the constructor definition and before the method definitions? Since the method definitions also use new Point(), which might confuse people if this isn't explained before

@zachwaffle4
zachwaffle4 force-pushed the stage0/classes-methods branch from 16c9f94 to a7a2b43 Compare July 29, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Curriculum material Curriculum materials, lessons for students, etc examples stage0

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

3 participants