What is the best design pattern to design the interface of an WebPage?

倖福魔咒の 提交于 2019-12-24 09:16:47

问题


I am trying to build the interface of my WEB site using OOP. For this I need to have several objects like menu, thumbnails, contentBoxes joined together to form a complete layout.

I know OOP is not used for presentation but I need to do it anyway. Can anyone help me on this?


回答1:


Look into the Model-View-Controller Pattern




回答2:


You can start with something really simple like all object inherit from this interface or abstract class where you have a method called render() that spits all the html out. The building of the html is ditacted by the value of your properties, say a menu as a collection of link objects, in render you build all the html for those links.

Going one step furter you can start modeling the properties of your objects say divs have child elements, so you can allow certain objects (inherit from the Interface IBlockElement) to have other objects as childs (Interface IInlineElement).

You can the implementn implement it in a way that when the parent object renders all child elements render methos is also called. Say you do $page->render() and all the inner elements would render, spitting all your html.

This is mainly from my experience developing in .NET Hope this makes sense



来源:https://stackoverflow.com/questions/2930300/what-is-the-best-design-pattern-to-design-the-interface-of-an-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!