2013/5/17 Tedd Sperling <tedd.sperling@xxxxxxxxx> > Nick: > > I thank you for your addition, but what you provided did nothing to > explain the difference between abstract and interface. > > In your example: > > An abstract Shape with Circle and Square inheriting. > > OR > > An interface Shape with Circle and Square implementing. > Does exactly the same thing -- so where's the difference? > > - The first one allows to contain implemented methods. Interfaces enforce "contract only", which makes them more stable on the long run. Sooner or later (or right from the beginning) someone _will_ implement a method in that class, which will loosen the separation between the contract and the implementation. And then it begins, that it is hard to distinguish, what from this class is contract (and should _never_ change without a good reason) and what is implementation, that can change. - It is semantically different as first one states "Circle _is a_ Shape", whereas interfaces defines their relationship more like "Circle _behaves like_ a Shape". - In many languages you can only extend from one class. Of course: Technically they do the same, but thats not the point ;) Also technically you don't _require_ interfaces at all. As mentioned: Most of this happens in ones mind. For example if you change an interface, you should _always_ expect to break something ;) Most of OOP isn't about syntax or technical features anyway, but it is about concepts (design and so on). And as a sidenote: I don't say (and don't believe ;)) that my explanation is completely academically correct ;) > > Also, your: > > Please make an effort to understand polymorphic concepts of OOP as > they are rudimentary. Without that one will never grasp OO Patterns > (Gang of Four). > > Was more insulting than helpful. Polymorphism was not the question asked. > > Clearly the getArea() method is polymorphic and overridden in both Circle > and Shape classes and also in BOTH abstract and interface examples. > > Additionally, I'm not sure what: > > > (int double side) > > means. > > Cheers, > > tedd > > > _____________________ > tedd.sperling@xxxxxxxxx > http://sperling.com > > > ----- > > On May 16, 2013, at 8:47 PM, Nick Khamis <symack@xxxxxxxxx> wrote: > > > interface Shape { > > public double getArea(); > > } > > > > class Circle implements Shape { > > double radius; > > public Circle(int double radius) { > > this.radius = radius; > > } > > > > public double getArea() { > > return (radius * radius * 3.1415); > > } > > > > } > > > > class Square implements Shape { > > double side; > > > > public Square(int double side) { > > this.side = side; > > } > > > > double getArea() { > > return (side * side); > > } > > } > > > > > > Please make an effort to understand polymorphic concepts of OOP as > > they are rudimentary. Without that one will never grasp OO Patterns > > (Gang of Four). > > > > Ninus. > > > > On 5/16/13, Tedd Sperling <tedd.sperling@xxxxxxxxx> wrote: > >> Thanks to both Bastien and Sebastian: > >> > >> While I understand that an interface is like an abstract Class, in that > you > >> don't have to flesh-out your methods, but rather where you define > exactly > >> how Classes who implement that interface will be required to flesh-out > those > >> methods. But so what? What's the point? > >> > >> Without giving me complicated examples, just give me one simple example > that > >> illustrates the advantage of using an interface over writing a new Class > >> where you flesh-out whatever methods you want. After all, an interface > >> requires the same thing, does it not? > >> > >> As such, I just don't see the advantage interfaces bring. > >> > >> Cheers, > >> > >> tedd > >> > >> > >> _____________________ > >> tedd.sperling@xxxxxxxxx > >> http://sperling.com > >> > >> > >> > >> -- > >> PHP General Mailing List (http://www.php.net/) > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- github.com/KingCrunch