What is a null object, and when are they useful?

Tags:

If you’ve written code, you’ve probably used the value null to indicate some variable is not set. This is perfectly good, but did you know there’s more to nulls than just the value null? There is also a null object, which doesn’t really have anything to do with the value null, but its purprose is similar. How many times have …

Using a builder to construct complex classes

Tags:

Sometimes if you have a complex class, which needs to be set up in a specific way: Perhaps it takes a lot of constructor arguments, or often requires calling some setters. Having something like that can make it more difficult to understand the code. In a case like this, you may want to consider using a builder class, which is …

Avoiding endless switch-case structures with classes

Tags:

Imagine the following: you have some form elements that need to render themselves. You have saved them in a database, as your users must be able to modify the forms. You have a bunch of different kinds of elements: a text field, a longer textarea field, maybe a field used for entering dates. How would you determine, which kind of …

The problems faced by a common model interface in frameworks

Tags:

You sometimes see people asking why the Zend Framework (or some others) don’t provide a library for the Model part in MVC. While ZF provides data access classes in the form of Zend_Db and related components, it doesn’t provide any concrete examples of how you would implement a model class. This often confuses especially beginners. Providing a common base model, …

Food for thought: utilizing models in MVC

Tags:

“What is a model” and “Is Zend_Db_Table a model” seem to be asked once in a while on #zftalk. Frameworks say they have a full model available, thus they are MVC frameworks ORM libraries say they generate models. It seems the ActiveRecord pattern has become somewhat synonymous with model. Pádraic Brady wrote an excellent post on how models are misunderstood, …

What are the controller and model in MVC?

Tags:

A lot of people seem to be slightly confused about what the M and C, Model and Controller, of MVC are, in regards to web applications. What does the Model do? What does the Controller do? View is what everyone seems to know, though… I wonder why is that so? What is so confusing about Models and Controllers?