1

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?

Daniel Daranas
  • 22,454
  • 9
  • 63
  • 116
Starx
  • 77,474
  • 47
  • 185
  • 261
  • Is there a reason you want to punish yourself in this way? Websites are built in HTML for a reason, I've always hated having to instantiate a million classes just to get a simple output. – Steve Hill May 28 '10 at 16:32
  • @Stephen Orr, I hate to disagree with you on this, in an Web projects there are so many common layouts, and having a class initiate and display them, is far better than creating a similar layout for every page – Starx May 28 '10 at 17:07
  • In my experience is way better to use OO for the business logic and use a template engine for the html generation. – Luis May 29 '10 at 00:48

2 Answers2

2

Look into the Model-View-Controller Pattern

GSto
  • 41,512
  • 37
  • 133
  • 184
0

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

Luis
  • 5,979
  • 2
  • 31
  • 51