开发者

Problem creating a webpage in OOP pattern?

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 writ开发者_高级运维e codes in its methods, so how can i achieve a solution for this problem.


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 {}


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?


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜