设计网页界面的最佳设计模式是什么?
我正在尝试使用 OOP 构建我的网站界面。为此,我需要将菜单、缩略图、内容框等多个对象连接在一起以形成完整的布局。
我知道 OOP 不用于演示,但无论如何我都需要这样做。谁能帮我解决这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看模型-视图-控制器图案
Look into the Model-View-Controller Pattern
你可以从一些非常简单的事情开始,比如所有对象都继承自这个接口或抽象类,其中你有一个名为 render() 的方法,它可以吐出所有 html。 html 的构建由属性的值决定,例如作为链接对象集合的菜单,在渲染中为这些链接构建所有 html。
更进一步,您可以开始对对象的属性进行建模,假设 div 具有子元素,因此您可以允许某些对象(从接口 IBlockElement 继承)将其他对象作为子对象(接口 IInlineElement)。
您可以以当父对象渲染所有子元素时也调用渲染方法的方式实现它。假设你做了 $page->render() 并且所有内部元素都会渲染,吐出你的所有 html。
这主要来自我在 .NET 中开发的经验希望这是有道理的
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