Skip to content

Earth - Ting-Yi#28

Open
ichbinorange wants to merge 17 commits intoAda-C14:masterfrom
ichbinorange:master
Open

Earth - Ting-Yi#28
ichbinorange wants to merge 17 commits intoAda-C14:masterfrom
ichbinorange:master

Conversation

@ichbinorange
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? When we create an instance of the class by using .new method, ‘initialize’ method run. All the arguments that we passed to .new will pass into ‘initialize’ method to create a new object with those arguments.
Why do you imagine we made our instance variables readable but not writable? Because we don’t want users or the other people get a chance to break our code.
How would your program be different if each planet was stored as a Hash instead of an instance of a class? If each planet was stored as a Hash and I couldn’t use any instance of a class, it meant no instance variables or helper methods were allowed. Ex. planet1 = { name’: Earth’, color: 'blue-green', mass_by: 5.972e24, distance_from_the _sun: 1.496e8, fun_fact: 'Only planet known to support life’},…}, then every time I want to use this data, I need to point out planet1[:name] etc. Also, I need to assign parameters for every planet methods. It would be more complex to organize all the methods and local variables.
How would your program be different if your SolarSystem class used a Hash instead of an Array to store the list of planets? When using a Hash, @planets.push(planet) becomes @planets[planet.name] = planet. Especially for the method ‘find_planet_by_name’, I can call key directly to get the value and simply return @planets[planet.name].
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, it does. For planet, it handles single planet objects, and for solar_system, it deals with multiple planets.
How did you organize your require statements? Which files needed requires, and which did not? What is the pattern? require is to call gems and require_relative is to call the classes defined in the other files. Because main.rb uses the classes from planet.rb and solar_system.rb, main.rb needs require_relative. But for planet.rb and solar_system.rb, these two don't use the classes from other files, so they don’t use any require statements.

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