Add methods to initialize and access turtleList, and refactor turtle access methods for improved code consistency and readability.#4370
Add methods to initialize and access turtleList, and refactor turtle access methods for improved code consistency and readability.#4370walterbender merged 9 commits intosugarlabs:masterfrom Ashrafmuhmed:master
Conversation
|
The new methods look good, but don't we want to use them? |
|
I believe these new methods should be used because they improve encapsulation and make it easier to interact with the turtleList without directly accessing it. This aligns with the TODO suggestion. Do you have any concerns or suggestions? I'm happy to listen and make adjustments if needed |
|
I agree. But adding the methods is only Step 1. Now we need to use them instead of the .get() methods. |
|
Got it! I'll work on replacing the .get() methods with the new ones and update you once it's done. |
…ency and readability
|
@walterbender Let me know your thoughts! I also noticed that elements were being added to turtleList directly, so I introduced a new method to handle this process more cleanly. |
js/turtles.js
Outdated
| * @param {Object} turtle | ||
| */ | ||
| pushTurtle(turtle) { | ||
| if(!this._turtleList.includes(this)) |
There was a problem hiding this comment.
should this be includes(turtle)?
There was a problem hiding this comment.
You're absolutely right! It should be includes(turtle) to check for the existence of the turtle before pushing it in the next line. Thanks for catching that! I'll fix it.
|
There are many references to turtleList outside of turtles.js. We'll need to check those as well to see where we need to make changes. |
|
Yeah, I know. I'm already working on them. I was just looking for your thoughts! |
|
Hi @walterbender , I have added methods to initialize and access turtleList. I also put significant effort into refactoring the turtle access methods to improve code consistency and readability. Please review the changes and let me know if any further improvements are needed. Thanks! |
Description
This pull request implements the following methods in the Turtles.TurtlesModel class in js/turtles.js related to issue #4369 :
Tasks