Due to a cold I had some time to think in the last few days (besides drinking tea, sleeping a lot, and watching videos). One thing I thought about was the Model class and how it could be improved.

If you look carefully at the API of the Model class, you will see that the current implementation assumes quite a bit about your models which doesn’t have to be true. So it assumes that you want to be able to find, update, save, and delete records through the model. Even though that’s often the case, it’s not always true. For example, you may want to have a read-only model. It’s something you cannot implement elegantly with CakePHP, as your model will always inherit methods like deleteAll(), save(), etc., and so those methods are part of the API of your model…

There are at least two possible ways to improve this.

The first approach is to make all such methods in Model protected. That means you could use those methods only from within your models. If you want to provide a delete-method, you would have to explicitly define such a method in your model and to delegate to the appropriate method from Model. The disadvantage of this approach is that it probably breaks a lot of code…

The second idea is to split the aforementioned functionality of the model into different behaviors. When writing your own model you can then choose which behaviors your model should have. For example, your model would use a “deletable” behavior if it should allow to delete records.

I am sure there are better ways than those I described here. They are simply thought as an inspiration to think about improving the model and to make it less fat ;-)