Skip to content

Space - Lee#21

Open
theomoondev wants to merge 22 commits intoAda-C13:masterfrom
theomoondev:master
Open

Space - Lee#21
theomoondev wants to merge 22 commits intoAda-C13:masterfrom
theomoondev:master

Conversation

@theomoondev
Copy link

Assignment Submission: Solar System

Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.

Reflection

Question Answer
When does the initialize method run? What does it do? The initialize method is called when an instance of a class is created (e.g., Planet.new). It is used to construct a new object of the associated class. It can accept arguments and store them as instance variables within the class methods.
Why do you imagine we made our instance variables readable but not writable? We made them readable so we could access their values in other files, but not writable so they could not be changed by the user.
How would your program be different if each planet was stored as a Hash instead of an instance of a class? Each SolarSystem would be an array of hashes, and each Planet would be a hash within that array. The planet details would be stored as key-value pairs in each hash (e.g., earth = {name: "Earth", color: "blue-green}. The entire program would likely be coded in one file or with just one other file for defining the SolarSystem class. Each time I wanted to access a detail of a planet, I would need to refer to it by its key rather than call a class method (e.g., planet[:name] instead of planet.name). Adding new planets would require methods that create a new hash and shovel it into the array of planets, rather than passing arguments through Planet.new.
How would your program be different if your SolarSystem class used a Hash instead of an Array to store the list of planets? In solar_system.rb, I would need to add @planets = Hash.new to the initialize method of the SolarSystem class, and I might store each Planet instance as a key-value pair (e.g., {earth: #<Planet:0x00007ff472138ff8>, mars: #<Planet:0x00007ff86f8ccdb8>}). I would also need to change the iteration variables (e.g., from planet to key, value) in the enumerable methods I used for the list_planets and find_planet_by_name methods. I would also need to change the code block of these methods so I could access the planet name through its key rather than within the class method (e.g., planet[:name] instead of planet.name). This would probably break a lot of things and require some experimentation with the data structure to work properly!
There is a software design principle called the SRP. The Single Responsibility Principle (SRP) says that each class should be responsible for exactly one thing. Do your classes follow SRP? What responsibilities do they have? Yes, I believe my classes follow SRP. The Planet class is responsible for handling the creation of new planets, which includes storing planet details to instance variables and returning a summary. The SolarSystem class is responsible for handling the creation of new solar systems, which includes grouping and finding planets within each system.
How did you organize your require statements? Which files needed requires, and which did not? What is the pattern? I organized my require statements at the top of the main.rb in order of file creation (i.e., require_relative: 'planet' is at the top since it was the first file created). I also added require statements to the planet_test.rb file, although I didn't have time to get my minitests working. The files solar_system.rb and planet.rb did not need require statements.

saraleecodes added 22 commits February 18, 2020 15:43
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.

1 participant