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 trialScott Odle
1,479 PointsWhy accept a "sides" parameter for the square at all? Squares always have 4 sides.
Doesn't make much sense.
4 Answers
Steve Hunter
57,712 PointsYep - true! But that shouldn't get in the way of getting the assignment challenge complete though, eh?! ;-)
Steve.
Chris Nash
Courses Plus Student 1,402 Pointshaha
Jared Watkins
10,756 PointsA square will always have 4 sides, but other shapes will have other numbers of sides. So, the property 'sides' should be declared in the base class 'Shape' and it should be a constant. Doing it this way makes the 4-sidedness a property of a square. This will translate nicely to another object, too.
Steve Hunter
57,712 PointsHi Jared,
I'm not sure we want all instances of shape to have 4 sides, or do I misunderstand you?
Steve.
Jared Watkins
10,756 PointsHi Steve,
Yeah, I didn't say that very clearly.
The sides property should be in the Shape class since all shapes have some number of sides, including even 1 or 0. Initializing the number of sides to 4 should happen in the convenience initializer for the Square subclass since a square will always have 4 sides.
This way, not all instances of Shape will have 4 sides - only the Squares will.
Leonardo Cavalcanti
5,308 Pointsthe computer doesn't know that!
Harold Davis
Courses Plus Student 14,604 PointsThis will be an interesting assignment
Mahdi Pedramrazi
2,505 PointsMahdi Pedramrazi
2,505 PointsI think logically the initializer for the
Square
class needs to accept onlysideLength
as a parameter. Since all Square shape object shave the same name and sides.