Re: aggregation?

php.internals

Wei He

23 years ago
On Thu, 26 Jun 2003, Sebastian Bergmann wrote:
> Wei He wrote: > > How could I live without aggregation or multiple inheritance? > > Java developers are very happy without these concepts. Why? Because > they have interfaces. Guess what? We have them, too.
If I understand correctly, using of interfaces will force a subclass to implement an interfaced method even if this method behaves the same as one of its parent classes. If so I'll have to copy method codes from parent classes like what I have do so in PHP4 without aggregation. Right? Wei He

(Marcus Börger)

23 years ago
Hello Wei, Thursday, June 26, 2003, 11:16:16 AM, you wrote: WH> On Thu, 26 Jun 2003, Sebastian Bergmann wrote:
>> Wei He wrote: >> > How could I live without aggregation or multiple inheritance? >> >> Java developers are very happy without these concepts. Why? Because >> they have interfaces. Guess what? We have them, too.
WH> If I understand correctly, using of interfaces will force a subclass to WH> implement an interfaced method even if this method behaves the same WH> as one of its parent classes. wrong A class that implements interfaces inherits all methods defined in the interfaces as abstract methods. In other words the class is abstract if not all interface methods are implemented. From there normal inheritance rules apply. WH> If so I'll have to copy method codes from parent classes like what I WH> have do so in PHP4 without aggregation. Right? No, the method implementations are inherited.
-- Best regards, Marcus mailto:helly@php.net

Wei He

23 years ago
On Thu, 26 Jun 2003, Marcus Börger wrote:
> WH> If so I'll have to copy method codes from parent classes like what I > WH> have do so in PHP4 without aggregation. Right? > > No, the method implementations are inherited.
Got it. Many thanks. So if I understand correctly this time, it will make no difference from MI when there is no overlap method and property in all parent classes. Can anyone give an example script demostrating how interfaces look like in PHP5? Wei He

Sebastian Bergmann

23 years ago
Wei He wrote:
> Can anyone give an example script demostrating how interfaces look like > in PHP5?
http://www.sebastian-bergmann.de/talks/adam-2003-oop.pdf
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ http://www.professionelle-softwareentwicklung-mit-php5.de/

(Marcus Börger)

23 years ago
Hello Wei, Friday, June 27, 2003, 3:36:11 AM, you wrote: WH> On Thu, 26 Jun 2003, Marcus Börger wrote:
>> WH> If so I'll have to copy method codes from parent classes like what I >> WH> have do so in PHP4 without aggregation. Right? >> >> No, the method implementations are inherited.
WH> Got it. Many thanks. No, you didn't. WH> So if I understand correctly this time, it will make no difference from MI WH> when there is no overlap method and property in all parent classes. Sorry, but this is no OOP teaching class. Maybe you have a look at this: http://talks.php.net/show/php5intro?PHPSESSID=63d210273967af7c74e034d92c2bf5e5 but namespaces a removed from the language. Best regards, Marcus mailto:helly@php.net

Wei He

23 years ago
On Fri, 27 Jun 2003, Marcus Börger wrote:
> Hello Wei, > > Friday, June 27, 2003, 3:36:11 AM, you wrote: > > WH> On Thu, 26 Jun 2003, Marcus Börger wrote: > > >> WH> If so I'll have to copy method codes from parent classes like what I > >> WH> have do so in PHP4 without aggregation. Right? > >> > >> No, the method implementations are inherited. > > WH> Got it. Many thanks. > > No, you didn't.
You are right I didn't.
> > WH> So if I understand correctly this time, it will make no difference from MI > WH> when there is no overlap method and property in all parent classes. > > Sorry, but this is no OOP teaching class. Maybe you have a look at this:
Sorry for that. I didn't know anyhing about interfaces until I had to seek for a solution for lacking of multiple inheritance. I'll keep silent to accept what php5 can give me. Just one last question: How, using php5 interfaces, can one avoid implementing method 'doit' twice? Thanks. class foo {...} class bar {...} class foobar { function doit() { echo "doing it."; } } class f extends foo, foobar {...} class b extends bar, foobar {...}
> http://talks.php.net/show/php5intro?PHPSESSID=63d210273967af7c74e034d92c2bf5e5 >
It's very interesting. Thanks.
> but namespaces a removed from the language. >
Best, Wei He

(Marcus Börger)

23 years ago
Hello Wei, Friday, June 27, 2003, 12:09:04 PM, you wrote: WH> On Fri, 27 Jun 2003, Marcus Börger wrote:
>> Hello Wei, >> >> Friday, June 27, 2003, 3:36:11 AM, you wrote: >> >> WH> On Thu, 26 Jun 2003, Marcus Börger wrote: >> >> >> WH> If so I'll have to copy method codes from parent classes like what I >> >> WH> have do so in PHP4 without aggregation. Right? >> >> >> >> No, the method implementations are inherited. >> >> WH> Got it. Many thanks. >> >> No, you didn't.
WH> You are right I didn't.
>> >> WH> So if I understand correctly this time, it will make no difference from MI >> WH> when there is no overlap method and property in all parent classes. >> >> Sorry, but this is no OOP teaching class. Maybe you have a look at this:
WH> Sorry for that. I didn't know anyhing about interfaces until I had to seek WH> for a solution for lacking of multiple inheritance. WH> I'll keep silent to accept what php5 can give me. Just one last question: WH> How, using php5 interfaces, can one avoid implementing method 'doit' WH> twice? Thanks. You just found the major disadvantage between interfaces and MI. The solutionS to that is are very complex....and require often more typing then one would like to.
-- Best regards, Marcus mailto:helly@php.net

Wei He

23 years ago
> > You just found the major disadvantage between interfaces and MI. > The solutionS to that is are very complex....and require often more > typing then one would like to. >
As I never believed there is any better solution for MI. Now they are even going to remove aggregation. I think there need to be more discussions between developers and users on adding or removing an important feature. Wei He

Sebastian Bergmann

23 years ago
Wei He wrote:
> Now they are even going to remove aggregation.
It is gone.
> I think there need to be more discussions between developers and > users on adding or removing an important feature.
Users wanted interfaces. PHP 4 could not accomodate that wish. PHP 4 introduced aggregation as a (ugly) workaround. PHP 5 has a new object model and can accomodate the original user's wish. Hence no need and no place for aggregation in PHP 5. Also, I think you still did not get the difference between modelling your code (interfaces) and code reuse (inheritance). Either way, this discussion is off-topic here.
-- Sebastian Bergmann http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Das Buch zu PHP 5: http://professionelle-softwareentwicklung-mit-php5.de/