|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
PEACE WILL WIN
![]() ![]() ![]() ![]() Join Date: Feb 2005
Location: Beyond the seas there is a town
Posts: 504
|
inheritance
Hello firends
In C++,We can use multiple inheritance. But in PHP 5,A class can inherit from only one parent class.What is advantage of this? |
|
|
|
|
|
#2 |
|
Mlle. Ledoyen
![]() Join Date: Jan 2001
Location: UK
Posts: 7,312
|
Thread moved. This question is more suited to this forum
Sean ![]() |
|
|
|
|
|
#3 |
|
eschew sesquipedalians
![]() ![]() Join Date: Jun 2003
Location: Iowa, USA
Posts: 3,779
|
Simplicity. If you have multiple inheritance, and you inherit from two or more classes which define the same method, which one do you use?
Java got out of that particular nightmare by providing support for interfaces, a model which PHP5 has adopted as well. |
|
|
|
|
|
#4 |
|
Non-Member
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2003
Posts: 5,799
|
Composition is an alternative approach to take, to get around Multiple Inheritance, and offers far more advantages to you by the way
![]() I could explain some more if your interested... |
|
|
|
|
|
#5 |
|
eschew sesquipedalians
![]() ![]() Join Date: Jun 2003
Location: Iowa, USA
Posts: 3,779
|
BTW, PHP does support something resembling ruby mixins, which may suit your needs.
|
|
|
|
|
|
#6 |
|
PEACE WILL WIN
![]() ![]() ![]() ![]() Join Date: Feb 2005
Location: Beyond the seas there is a town
Posts: 504
|
Please more
Hello Firends
Dr Livingston Please explain more,I'm interested |
|
|
|
|
|
#7 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Jan 2005
Location: Belgium
Posts: 355
|
well... assume you have a class AB that has as parents A and B.
with composition you can define AB as: class AB extends A (could be B also) { private $_b; public function __construct() { $this->_b = new b; } // now implement all b-methods public function aBMethod { return $this->_b->BMethod(); } } i assume that with __call overloading things are even easier.. sometimes you don't want to inherit from one class, then you'll have a class AB that has a A and a B... enough possibilities to work-around the single-inheritance... |
|
|
|
|
|
#8 |
|
Resident Java Hater
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Gerodieville Central, UK
Posts: 479
|
In C++ you sort of need Multiple Inheritance for various tasks. For instance, if you want to use C++ interfaces with Pure Virtual Functions, you are forced to using classes as there is no direct support for interfaces. If you have a set of classes containing PVM's which want to implement in a given class you need MI to aggregate these interfaces.
C++ being a compiled / strict typed language obviously doesn't have the reflective properties of VM based languages like Java, ruby, & PHP. In fact early versions of the language didn't have any constistent form of the RTTI. Reflection often lets you inspect data types at runtime, which is needed if you want to aggregate classes using things like mixins / dynamic proxies / __call() overloading. In it's current state C++ lacks the level of reflection used by modern languages. Reflection allows us to avoid MI in favour of mixins, hence removing the complex rules that MI gives us, and giving the programmer more control instead of making the programmer work round the complex rules of C++ MI (Which gets very messy when you take into account things like different pointers, virtual methods, and the different array of casts, and templates). Remember also, PHP is a language to quickly make simple maintainable web pages. it's not designed like C++ to do just about anything after a load of hair loss. |
|
|
|
|
|
#9 | |
|
Resident Java Hater
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Gerodieville Central, UK
Posts: 479
|
Quote:
|
|
|
|
|
|
|
#10 |
|
Non-Member
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2003
Posts: 5,799
|
Enough said then... Phew
Don't like big speeches myself, and I'm never the one looking for an audiance either ![]() On the other hand though, if you need an indepth explamation, search for Multiple Inheritance over at www.javaworld.com ![]() This is where I started to poke around. |
|
|
|
|
|
#11 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Aug 2004
Location: California
Posts: 1,672
|
It is interesting how attitudes have changed on inheirtance. I think that progress in XP and TDD has had a big influence on it. Deep inheirtance, whatever its technical value, is not in the spirit of today's methodologies. Composition seems to have proven itself to be more flexible and testable, or at least feels that way. It has almost come full circle where inheirtance is now applied as Static Composition.
|
|
|
|
|
|
#12 | |
|
SitePoint Victim
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2003
Location: London
Posts: 2,273
|
Hi...
Quote:
yours, Marcus |
|
|
|
|
|
|
#13 |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Aug 2004
Location: California
Posts: 1,672
|
Interesting, and thanks for the book reference.
I think you are right about the patterns movement. A decade or two of experience building real applications certainly _field tested_ these concepts. And the fact that the platforms and even the types of applications have changed over the last decade has certainly had an effect as well. |
|
|
|
|
|
#14 |
|
eschew sesquipedalians
![]() ![]() Join Date: Jun 2003
Location: Iowa, USA
Posts: 3,779
|
I just finished reading Holub on Patterns during my "vacation"
Overall, I think the book is very solid, and did a good job of living up to it's sub-title of "explaining patterns through looking at code". The two examples were a Game of Life implementation and an embeded database which stored data in csv files and supported a SQL layer. The game of life example had a bit of "Patternitis" but was still very good. I think the db example was very realistic.Two things I think are great take aways which I may use in my upcomming talk on Patterns at php|tropics are the term "reification" and the concept of a UML pattern diagram superimposed on an abbreviated class diagram to show pattern relationships. This is very interesting, especially in the light of a) realistic naming (i.e. your class names should reflect their role in the domain model, not an arbitrary pattern name) and b) classes can be colaborators in more than one pattern at a time. Anyway, thumbs up from me on this book as well. |
|
|
|
|
|
#15 | |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Posts: 848
|
Quote:
|
|
|
|
|
|
|
#16 |
|
Non-Member
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2003
Posts: 5,799
|
Selkirk,
I'm aware of the single responsibility principle but not the other principle? Do you have a link to more information... Thanks ![]() |
|
|
|
|
|
#17 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Posts: 848
|
|
|
|
|
|
|
#18 |
|
Non-Member
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2003
Posts: 5,799
|
Thanks. Suppose I should've googled first before asking huh?
![]() Anyways, it's appreciated... |
|
|
|
|
|
#19 |
|
Floridian Opera Brigadier
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: Florida
Posts: 1,975
|
I think that C++ and multiple inheritance is an effective method for a variety of task, and I don't see a reason not to support it. Simply using a similar structure to C++'s method wouldn't hurt a bit and provide extended programming options.
PHP took too much out of OOP for someone coming from C++. I think multiple inheritance is one, but I'll grow away from it as it doesn't look like PHP is going to support it any time soon. |
|
|
|
|
|
#20 | ||
|
Non-Member
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2003
Posts: 5,799
|
Quote:
Quote:
![]() |
||
|
|
|
|
|
#21 | |
|
PEACE WILL WIN
![]() ![]() ![]() ![]() Join Date: Feb 2005
Location: Beyond the seas there is a town
Posts: 504
|
Interface or mutiple inheritance?
Hello
It's said: Quote:
I wanna know how can interface that What are advantages of using interface instead of Multiple inheritance?(Please give me an example) Last edited by abalfazl; Apr 22, 2005 at 03:41. |
|
|
|
|
|
|
#22 | ||
|
SitePoint Addict
![]() ![]() ![]() Join Date: Mar 2005
Posts: 214
|
Quote:
http://www.sitepoint.com/forums/showthread.php?t=252133 Haven't looked at PHP5 : it's great if it supports interfaces but my hosting provider doesn't support PHP5 yet . |
||
|
|
|
|
|
#23 |
|
PEACE WILL WIN
![]() ![]() ![]() ![]() Join Date: Feb 2005
Location: Beyond the seas there is a town
Posts: 504
|
Dear lady
Thank you very much for your answer Please explain by code.Then It will be more clear for me |
|
|
|
|
|
#24 |
|
SitePoint Zealot
![]() ![]() Join Date: Jan 2005
Location: United Kingdom
Posts: 199
|
I am still learning the use of interfaces, but here is an example - sorry if it is nonsense
![]() We write a class called Car. This implements an interface IVehicle which gives some basic methods about a Vehicle. We could use an abstract class here but we use an interface because it allows more flexibility. PHP Code:
PHP Code:
PHP Code:
|
|
|
|
|
|
#25 | |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Mar 2005
Posts: 214
|
Quote:
When you will code interfaces you will be faced with the "bureaucracy" of interfaces you will have to deal with supplemental interfaces variables declarations. You could be fed up and wonder if it's worth the pain then only you would perhaps need to remember the above answer . So at the moment you can just forget it if all you need is the syntax - which has been given above so I don't need to thanks Shrike .Now I'm not sure of the real interest of interfaces just for generating web pages, normally it's rather used for business objects like the EJB in Java. In fact I suspect that since SUN endorsed PHP recently they need that PHP programmers get used to some programming paradigms necessary to attack java interfaces from PHP: SUN business is to sell Business Application Servers that's where the value in $ is, they care less about JSP containers which can be found for free and as JSP is not as widespread as PHP strategically it's well done. |
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 23:26.










Don't like big speeches myself, and I'm never the one looking for an audiance either 


Linear Mode
