Jump to content

OOP - Some questions regarding final, interface, implements, extends


Recommended Posts

Hey after some googling and reading, have i come to a certain page in my life, that i got stuck! I'm a huge fan of normalisation (it makes atleast my life a bit easier) so now am i trying to do this also on some oop (object oriented programming - for those who do not know what i mean)

So if interface, implements, extends, etc... is no foreign language for you, then please feel free to be so kind and enlight my mind... xD

Thanx in advance,
Ignace
This may help with some of the questions.

http://www.phpfreaks.com/forums/index.php/topic,104878.0.html

An interface is similar to a parent class except it has no code defined in it, just a list of method declarations which the implementing class must define.
an interface provides rules for an objects relational accessibility (i.e. interface)

Much like USB has a certain shape to it's plugs, a class interface defines the access points.

Abstract classes are simply parent classes that must be extended in order to use them. You can specify abstract methods that must be overloaded by the child class, whilst also maintaining common functionality amongst those child classes within the parent abstract class.

Classes can only extend one parent, but can implement many interfaces.

Final is the opposite of abstract. It cannot be overloaded/extended.
thx for the information, @barand so an interface is much like the prototypes that you can define in c++? but now you use a child class to implement them instead of adding them after [ int main(); ]
k, thx, now something else, overloading is this done in the same way as in c++?

string doMyHomework(string Input);
string doMyHomework(double Input);

however i can not define the return type or the argument type

function doMyHomework($Input);
function doMyHomework($Input); // cannot redeclare function 'doMyHomework'

so how do i overload a php function?
As php isn't a strongly typed language like C it doesn't really apply.
[code]<?php
function doubleMe ($input) {
    return $input * 2;
}

$x = "2";        // string
$y = 2.75;      // float
$z = 3;          // int

echo doubleMe($x);
echo '<br/>';
echo doubleMe($y);
echo '<br/>';
echo doubleMe($z);
?>
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.