23.3. Try Implementing Design Patterns

While I'm not a fan of "homework," I am a fan of hands-on learning. You've seen me take this application through a portion of a second iteration by applying more Design Patterns to the code. The work is not done, however. I encourage you to take a look at the following areas that can be based on some Design Patterns. Try your hand at implementing your own version of the Design Pattern against this working code base.

23.3.1. Design Patterns and Error Checking

A good portion of the application is void of error checking. The only real error checking put in place is in user creation. The process simply makes sure that the user does not exist. What other ways could you implement error checking using PHP Design Patterns?

You may investigate into using the Strategy Design Pattern to check various types of strings for a valid type. For example, knowing that a username or a password should not be a blank string, a Strategy class validating that the string contains at least one character could be created.

For more on the Strategy Design Pattern, see Chapter 17.

Another route to take would be to have a Visitor object visit the instance of the dao before the save() method is called. The visitor could validate the required fields and flag the dao as valid or not. This could happen during both the creation and modification processes.

You might also create a method named isvalid(), which makes use of some Delegate objects to check various properties ...

Get Professional PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.