Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 29 September 2006 - 05:39 PM

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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 September 2006 - 06:12 PM

This may help with some of the questions.

http://www.phpfreaks...c,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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 29 September 2006 - 06:31 PM

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.

#4 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 29 September 2006 - 06:43 PM

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(); ]

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 September 2006 - 06:50 PM

Slightly different emphasis. Prototypes tell you what is defined, interface tells what must be defined for the class to function correctly
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 ignace

ignace
  • Moderators
  • Now mod flavored
  • 6,431 posts
  • LocationBelgium

Posted 30 September 2006 - 11:53 AM

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?

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 September 2006 - 09:34 PM

As php isn't a strongly typed language like C it doesn't really apply.
<?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);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users