Pregunta

I have a page that, when accessed displays a table of information related to a video:

  • Embed code
  • Title
  • Description
  • Current gallery
  • Thumbnail image

This information is read-only when the page is first accessed.

There is a select menu that has the following options:

  • Edit Description
  • Create Thumbnail (Upload/Replace)
  • Edit embed code
  • Change Gallery
  • Delete video

When the user selects an option, the same initial table of data is displayed, but the relevant form input is displayed where necessary.

For example, if "Edit Description" is selected, the page reloads and the description text is replaced with a text input. If "Create Thumbnail" is selected, then a file upload input is displayed.

The idea is to display all of the information together but to limit how much can be edited at a time.

I know the state pattern is a possible solution, since each piece of data can be in atleast one of two states:

  1. Display State
  2. Form input state

But, my question is, would using the state pattern be overkill?

At the moment, each time the page is accessed, each part of the form decides with a switch statement whether it should be in 'display' or 'input' state and then acts accordingly. I wonder if implementing the state pattern design would make altering the form and creating similar forms easier down the road.

Thanks!

¿Fue útil?

Solución

No, the state design pattern isn't overkill. It's probably a very good choice of algorithm for handling such a complex interface. I've used state engines in PHP several times; it helps you think creatively about the problem and you often get a bonus in flexibility.

I wish more programmers knew of such things.

Otros consejos

The more I use design patterns, including the State pattern in PHP, the more I'm convinced that they save time. Initially, it may take longer to develop, but not much longer. However, when it comes to change and update, they save huge amounts of time. Your code is better organized, clearer and less likely to through a bomb into your code that you get with the tight binding outside of design patterns. I've done several PHP design patterns at php5dp.com, but, nothing in a State dp.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top