Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialvamosrope14
14,932 PointsWhy do we not include parameters in the constructor method for the library class?
.
3 Answers
Steven Parker
231,248 PointsParameters are always optional, it's perfectly legitimate to have a class that can be instantiated without any.
Clinton Hays
Front End Web Development Techdegree Graduate 18,156 PointsIn this particular case, we aren't setting parameters on the constructor method because we will populate the arrays with the other objects we're building. If we add parameters now, we'd have to create each instance of a new Library with those two parameters instead of just being able to dynamically adding them after. There isn't anything inherently wrong with doing it that way, it just means you have to your patron and books arrays already constructed and ready to pass in when you make your new library.
If you add parameters, they are mandatory when creating your new object. So, like Steven Parker mentions they are often used for setting initial values. SInce we're building a new Library, we won't have any Books or Patrons to pass into the LIbrary yet.
Hope that helps clarify a little further for anyone who may have this question in the future!
Christopher Brown
4,843 PointsThank you for the clarification!
Jenniffer Hernandez
Full Stack JavaScript Techdegree Student 11,662 PointsStill not totally sure when and why you need to pass parameters. Maybe I missed something in the videos/course.
Steven Parker
231,248 PointsParameters give you a way to pass data to a constructor that it will use for creating the object. Typically the data is used for things like setting initial values for internal variables. Depending on the design of the object, it may not need any.