Ross Tuck

Ross Tuck
November 21, 2013

Workshops, workshops everywhere

Ibuildings regularly organizes an internal workshop. (mostly) technical subjects are dealt with and further elaborated on on the basis of an assignment.

But how do you make a workshop on Symfony 2 and Domain Driven Design (DDD) interesting for everyone?

Just, by building a memegenerator.
Blog

Even though it may seem like a small and less technical challenge, there are certain components that you consciously or unconsciously apply in setting up a memegenerator. Here are a few examples.

Bundle format

To keep an overview, a clear layout of your bundles/packages is a must.

Naming

Just like when you draw up your entities, functions and variables, naming is oh so important. The same goes for your bundles.

So don’t use a common name like CoreBundle or MainBundle, but a more explicit name.

For example, in the workshop we have a MemeBundle and a Meme package. The Meme package contains all business logic/entities (DDD domain objects) and the MemeBundle takes care of the integration with Symfony.

Integration

A best practice is to include all integration with the Symfony framework in a separate bundle.

For the Memegenerator we use the ‘ImageGeneratorBundle’ as an ‘integration’ bundle for the use of the image generator class. Another good example is the authentication of users via Google oAuth.

Functionality

When you set up a large-scale project, you divide it into smaller sub-systems to keep your project manageable. By implementing this subdivision in your bundles, you get a much clearer overview of your Symfony project.

Also remember that the naming matches the terminology within your application (Ubiquitous Language) and the actual functionality, for example ‘NotificationMailerBundle’ instead of ‘MailBundle’.

Blog !

Value objects

One of the powerful concepts in DDD is the use of value objects. An important feature is that value objects never change (immutable).

A value object is ideal to include small functionality and validation. This also makes them easy to unit-testing. This reduces the chance of errors in your application.

In the workshop we use the entity ‘Meme’ to generate the image. A meme always consists of a ‘lead line’ and ‘punch line’. The title ‘Workshops’ is the lead line and ‘Workshops everywhere’ is the punch line.

You can place both lines in one Caption value object.

namespace Ibuildings\MemeBundle\Value;

/** * Meme Caption Value Object */ class Caption { private $lead; private $punchLine;

/\*\*
 \* Constructs a caption based on a lead and punch line.
 \*/
public function \_\_construct($lead, $punchLine)
{
    $this->lead = $lead;
    $this->punchLine = $punchLine;
}

/\*\*
 \* Lead of the Meme Caption
 \*
 \* @return string
 \*/
public function getLead()
{
    return $this->lead;
}

/\*\*
 \* Punch line of the Meme Caption
 \*
 \* @return string
 \*/
public function getPunchLine()
{
    return $this->punchLine;
}

}

A lot of other objects also qualify for use as Value objects.
Think of Money, DateTime and even Address objects.

Everywhere

As you can see: no matter how small or large a workshop/project is, best practices can be applied everywhere!

If you want to know more about these subjects, take a look at this: