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
'Data entity object' and PHP
Moderator: General Moderators
-
Jeroen Oosterlaar
- Forum Commoner
- Posts: 37
- Joined: Sun Nov 06, 2005 4:12 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Jeroen Oosterlaar
- Forum Commoner
- Posts: 37
- Joined: Sun Nov 06, 2005 4:12 pm
Okay thanksCharles256 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
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
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;)
Last edited by Charles256 on Sun Nov 06, 2005 5:08 pm, edited 1 time in total.
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.
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.