-1
\$\begingroup\$

The context:

I am currently struggling with a conception problem: I am building a SEO tags generator in PHP. I already managed to render some beautiful tags like these:

<meta name="keywords" content="look, at, my, horse" />
<meta property="og:title" content="My horse is amazing" />
<meta http-equiv="Cache-Control" content="no-cache" />
<link type="application/rss+xml" rel="alternate" title="RSS" href="http://feeds.feedburner.com/martini" />
<link type="application/json" href="http://facebook.com/leogout.json" />

Which are represented like this in my model: Class diagram of the meta and link tags

They are then manipulated with some builders:

Class diagram of the builders for meta and link tags

In the render() method, they iterates over their collections of tags and renders every tags + concat them together in a big pile of... HTML.

If there are already some OOP problems or misconceptions, don't hesitate to give me some advice about them too !

The problem:

So far so good, now I have to render an unique <title><title/> tag. I added a TitleTag to the model and a TitleTagBuilder like this:

Aaah I need more than 10 reputation to post more links :S Well...

                      +------------------+
                      |TagBuilderInterface
                      +------------------+
                               ^
                               |
                      +------------------+
                      |AbstractTagBuilder|
                      +------------------+
         +-----------------^   ^   ^------------------+
         |                     |                      |
         |                     |                      |
         |                     |                      |
+-------------------+  +------------------+  +-----------------------+
|MetaTagBuilder     |  |LinkTagBuilder    |  |TitleTagBuilder (NEW!) |
+-------------------+  +------------------+  +-----------------------+

But now what can I do with my AbstractTagBuilder ? It only knows how to render a collection of tags, but I don't think it's a good thing that users can add multiple <title> tags to their web pages. Should I create an AbstractUniqueTagBuilder or something ? How would you solve this problem ?

Thanks for your time.

PS: The diagrams are generated with PhpStorm except for the last one which is generated with asciiflow (can't post the link either...) in case you were wondering :)

\$\endgroup\$

closed as off-topic by Mike Brant, alecxe, Jamal Apr 11 '17 at 3:31

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Jamal
  • "Questions must involve real code that you own or maintain. Pseudocode, hypothetical code, or stub code should be replaced by a concrete implementation. Questions seeking an explanation of someone else's code are also off-topic." – Mike Brant, alecxe
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Where is code to be reviewed? \$\endgroup\$ – Mike Brant Apr 10 '17 at 23:03
  • \$\begingroup\$ Welcome to StackExchange Code Review! On this site we review working code. Suggest you take a look at these Guidelines \$\endgroup\$ – Stephen Rauch Apr 10 '17 at 23:55
  • \$\begingroup\$ Hey thanks ! I read the help before posting but i didn't realized that. Do you know if there is a kind of forum that talks about oop conception ? Thank you ! \$\endgroup\$ – Leogout Apr 11 '17 at 6:44
  • \$\begingroup\$ @Leogout Try softwareengineering.stackexchange.com \$\endgroup\$ – Mike Brant Apr 11 '17 at 13:28
  • \$\begingroup\$ Thank you Mike, It's exactly what i was looking for. Cheers! \$\endgroup\$ – Leogout Apr 11 '17 at 15:36
1
\$\begingroup\$

Honestly, this seems way over-engineered for such a simple process. Maybe you're just trying to learn OOP concepts, but I don't think anyone would be using Builders and Interfaces and "render collection of tags" and all that for what seems to be just taking a few tags and outputting them as HTML.

Rather, take an array of tags and pass it to a template (e.g. Smarty). Super simple and appropriate tool for the job. I'd save the overwrought OOP for where it's actually needed. Trying to shoehorn a simple task into a 4-layer abstracted interface is just going to produce awkward results that aren't representative of how you'd really use OOP in practice.

\$\endgroup\$
  • \$\begingroup\$ +1 I don't even need to answer here, because this says it all. This is like using a chainsaw to cut a piece of paper. \$\endgroup\$ – Mike Brant Apr 10 '17 at 23:05
  • \$\begingroup\$ Aha that's a good point ! You are right it was trying to get a better understanding of OOP and design patterns in general. I overthought the thing. I won't accept the the answer as it doesn't help me to solve this particular problem, I still don't know what to do in such situation, but here is a +1 for your time. Thanks ! \$\endgroup\$ – Leogout Apr 11 '17 at 6:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.