Page 1 of 1

'Data entity object' and PHP

Posted: Sun Nov 06, 2005 4:31 pm
by Jeroen Oosterlaar
Hi everyone,

With the release of PHP 5 developing PHP applications using an OOP approach is getting more and more interesting. I would like to read your opinions regarding to what extent OOP should be implemented. My regular approach is the model-view-control one. I use the Smarty template engine to separate the business logic from the presentation logic and within the business logic layer I usually separate the paging business logic (handling the post actions, headers and template assigning and parsing) on the one hand and the model modifier business logic (inserting new records in the databae, selecting records etc.) on the other.

I have quite some experience in the field of web development using Java and within the Java environment it is common to use so called Java beans to describe data. For example a datasource table named User which describes the properties of a system user should be used within the Java environment as a bean that has the exact set of properties as variables that can be retrieved and set by the business logic.

At this moment, within PHP, I use array's to 'transport' database data within the application, but I was wondering to what extent the Java approach, I just described, is suitable within the PHP environment. In other words: is it a good practice to create a class for every database entity to work with within the business logic layer?

Thanks in advance!

Jeroen

Posted: Sun Nov 06, 2005 4:39 pm
by Charles256
to sum it up...
someone: take OOP all the way
someone else: stick with procedural
third party: find something in the middle
me: do what works for you.
someone else: do what works for me.

tada

Posted: Sun Nov 06, 2005 4:42 pm
by Jeroen Oosterlaar
Charles256 wrote:to sum it up...
someone: take OOP all the way
someone else: stick with procedural
third party: find something in the middle
me: do what works for you.
someone else: do what works for me.

tada
Okay thanks ;), so you are basically saying that it doesn't matter at all? But knowing that PHP is going the OOP direction, there surely must be some preferable design, doesn't it?

Posted: Sun Nov 06, 2005 4:59 pm
by Charles256
i'm saying everyone has their own opinion and noone's changing. so do what works for you. just because a language is OO doesn't mean you can't write procedural code;)

Posted: Sun Nov 06, 2005 5:06 pm
by feyd
read through the previous threads on OO and how far to go.. we will not rehash (or reignite) that question anymore.

Posted: Sun Nov 06, 2005 7:02 pm
by McGruff
OOP works very well in php - v4 or v5 - so your Java experience will transfer over. Personally I wouldn't write procedural code for anything except a simple shell script with a dozen lines of code.

Php is a scripting language of course which will have an affect on design. With everything created and destroyed per request, patterns like LazyLoading are maybe more important. The balance between Transaction Script and Domain Model possibly swings slightly towards the former in a scripting language - but don't be afraid to go all out for a domain model, Data Mappers etc if you have complex domain logic and objects which don't map neatly to db tables.

Were you XP-ing in Java? SimpleTest is a great little unit testing framework with mock objects and a web tester. If not, we've got a unit testing forum here where you can find out more.

There's also phpUnit (sorry no link). Last time I looked it didn't have mock objects, although these are planned.