alvarito Posted August 29, 2011 Share Posted August 29, 2011 Hello, On page 301 where it declares the abstract class and on the next page where it extends it, it turns out that no attribute is declared in the parent but only in the child class, namely triangle class. Since the parent is called "shape", wouldnt one put the main attributes there such as "$side" so that other shapes like rectangle can also use that ?. What would we do then when we create another extension like "class rectangle extends shape" , we are going to need the $sides again. thank you A Link to comment Share on other sites More sharing options...
Jonathon Posted August 29, 2011 Share Posted August 29, 2011 Yes you will need $sides again, but this is one of the underlying principles of more advanced OOP. The parent class is a framework for the sub class to take minimal information from and develop it's own set of methods for that particular shape. The $sides property can never be used by the Shape class and overwriting the Shape property each time you extend the class goes against the ideas of how OOP should be used. Link to comment Share on other sites More sharing options...
Jonathon Posted August 29, 2011 Share Posted August 29, 2011 I am questioning myself now Link to comment Share on other sites More sharing options...
Larry Posted August 30, 2011 Share Posted August 30, 2011 Jonathon's not far off, but my main reason was that a circle is a shape with an area and a perimeter but no sides. Link to comment Share on other sites More sharing options...
Jonathon Posted August 30, 2011 Share Posted August 30, 2011 Well I did think about that but then started to think, in my mind that I couldn't see a problem with declaring a property in the abstract class. Something like private $side; But then didn't put those 2 ideas together into a form of an answer as I confused myself. Thought it was best to wait for a difinitve answer Link to comment Share on other sites More sharing options...
alvarito Posted August 30, 2011 Author Share Posted August 30, 2011 Thank you. It is clear to me now ================================= Yes you will need $sides again, but this is one of the underlying principles of more advanced OOP. The parent class is a framework for the sub class to take minimal information from and develop it's own set of methods for that particular shape. The $sides property can never be used by the Shape class and overwriting the Shape property each time you extend the class goes against the ideas of how OOP should be used. Link to comment Share on other sites More sharing options...
Recommended Posts