tags:

views:

57

answers:

3

I want to develop a website in OOP pattern, but I am stuck in a point whether I need to inherit from multiple classes.

For example I have a main class "index" this class has several methods which need to inherited from other classes and I have created seperate classes for it like

class "banner", class "content", class "footer"

Not only this but class "content" has several methods to be inherited from other classes like

class "gallery", class "news", etc

I found out that multiple inheritance is not allowed, and using interface I cannot write codes in its methods, so how can i achieve a solution for this problem.

+1  A: 

I have no idea of the functionality of the classes, but just a thought:


class Index {
...
}

class Content extends Index {
...
}

class News extends Content {
...
}

If the contexts of those classes don't fit, you might want to re-think about the design and functionality of your classes.

EDIT

I don't want to come across brash, but if you can't figure out a good inheritance / design pattern maybe you should stick to a well thought out, already existing framework?

mmattax
Yes, I was using the chaining pattern like yours, but I came across problem when the classes i am chaining has others chaing also. I think you understood what I am trying to achieve here, Is there a simple way for this, rather than going for a different framework
Starx
A: 

I think you need to think of it as a Page object contains several controls (header, footer, content) which themselves can contain controls (News) which can contain controls (text, label, picture) etc...

Chad
alright, how to create these controls?
Starx
Controls is another base class that implements a control interface (you define), and your different controls (header, footer, banner) extend. Your page, is effectively just a container for controls. And since controls can contain other controls. Your page too, is just another extension upon control.
Chad
I am not a PHP expert, so could you please post a example of these controls
Starx
A: 

You could have a main abstract class http://php.net/manual/en/language.oop5.abstract.php which is similar to interface but allows you to add code to the functions. This can include methods that are similar to gallery, news etc

class Gallery extends AbstractClass {}

Zach
No. class content needs to extends from gallery and news class like class gallery extends abstractclassgallery,abstractclassnews { }
Starx