Tuesday, July 21, 2009

Naked objects in Php

The validity of Naked Objects pattern, if implemented successfully, can add value to the php scene and help to answer the "Is Php ready for the enterprise?" question. Currently there is no framework to support this approach in the php world.

Php in the enterprise
The enterprise world has several architectural choices to build complex applications: Model-View-Controller frameworks are currently in vogue, especially in the php world, where Zend Framework, Symfony, Code Igniter, CakePhp and many others all implement this paradigm. But there are also examples in different languages: Ruby On Rails, Django for Python, Spring and Stripes for Java.
There is also a niche where developers are tired of bloated controllers and views that contains logic; they're also tired of dumping their own objects and get some megabytes of data because they have dependencies on all the instantiated objects of the chosen framework: here comes in NakedObjects.
As I wrote last week, the Naked Objects pattern let the framework take care of 3 of the 4 layers of an enterprise application: infrastructure, controllers and views are provided as generic or generated objects. The developer has only to write a Domain Model layer that follows some conventions.
Two frameworks that are named Naked Objects exist: one is written in Java and it is open source, while the other runs on the .NET platform; they are provided by the same people behind nakedobjects.org. Domain-Driven Design is really possible when using this tools.
I couldn't find a similar possibility for the average php programmer: it's a pity because php has the potential to introduce more and more cloud computing in the enterprise applications, let you use only a browser as a client.
There is also JMatter available, for Java.

Why wait?
So I decided to write a new one, a port of the Naked Objects for Java framework. It will have only a web interface anyway, since it is the best fit for php (no local GUI as it does not make sense).
Since I don't want to reinvent the wheel, it will incorporate Doctrine 2 (which I am contributing to) in the persistence part of the infrastructure layer and Zend Framework with its MVC implementation in the upper ones. Since the Naked Objects pattern has to be followed, the Views and Controllers will be provided from this framework, which I named NakedPhp. Obviously I chose an Open Source license, the bullet proof LGPL version 2; supporting DDD is also a key feature which I want to include.
Here are some links that points to the main resources activated on SourceForge to support the project:
Main page
Naked Php wiki
In-browser view of the Subversion repository
I will blog often about the architectural decisions of NakedPhp and its improvements, and when a alpha downloadable package will be available. Of course the repository is open to anyone who wants to take a look at the source code.
If you're tired to write controllers and views, consider the choice of a Naked Objects approach. And if you are a php developer and you want to participate, contact me!


Robert said...

Did you check out FLOW3 (http://flow3.typo3.org)? It specifically supports Domain-Driven Design, AOP and Dependency Injection. Very close to Naked Objects ..

Giorgio said...

FLOW3 is a full stack MVC framework, so it is comparable to Zend Framework and Symfony, but it is in currently alpha while Zend Framework is used in production. That means it could break API in every moment. I will read their manuals as I am interested in how they treated some issues.
For Doctrine 2 the problem is less serious since it is not invasive and NakedPhp will be less coupled to it, and I am actively involved in its development so I am aware of what changes every day. :)

Dan said...

Nice to see another implementation of the Naked Objects pattern about to start.

As one of the committers to NO on the Java platform, can I suggest you familiarize yourself with the reworked architecture we came up with for building the metamodel that sits at the heart. We use a bunch of (what we called) FacetFactory's which effectively define the programming model. We've haven't even scratched the surface of what this architecture will give us, but it's worked out really well. If you are starting afresh I strongly suggest you look towards a similar architecture.

See http://development.nakedobjects.org/trac/browser/framework/trunk/core/metamodel/src/main/java/org/nakedobjects/metamodel/specloader/progmodelfacets/ProgrammingModelFacetsJava5.java for more details.


Giorgio said...

@Dan: thank you for the pointers, I do not know where to search in the trunk. However, there is some developer documentation anywhere? I found the api and the application development guide, but not a view of the internal architecture of NOF.

Dan said...

Hi Giorgio,
there's a PDF at http://development.nakedobjects.org/trac/browser/framework/trunk/How%20to%20build%20Naked%20Objects%20from%20source.pdf
that says how to build the whole thing if you want.

We do need to put together some architectural diagrams though; I'm just finishing off my book on DDD and Naked Objects (at http://www.pragprog.com/titles/dhnako/domain-driven-design-using-naked-objects) so once that's out of the door then I'll put some things together.

If you do download the Java code, I can talk you through it, though.


Giorgio said...

Thanks, I am currently busy at work but I'll take a look at the source when I have finished this stuff.

Dan said...

Hi Giorgio,
here you go, a picture for you: