Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where does OOD fit into PHP/MySQL web apps?

Status
Not open for further replies.

MasterKaos

Programmer
Jan 17, 2004
107
GB
I learnt a lot about OOD at uni, and really enjoyed developing applications using OO languages like Java and C++. Since finishing Uni I have taken a different path than I expected, as at the time there was shortage of Java / C++ jobs, and a surplus of graduates. So I decided to start my own business, which has become quite successful, mainly developing small to medium sized web based applications, using PHP and MySQL.

Now I have embarked on a large project and I am developing a functional specification using UML. Using OOD principles is very much helping me define the requirements and functions of the system. But whereas OOD maps directly to languages such as Java / C++ I am a bit confused how it relates to PHP scripts and MySQL databases.

In terms of PHP/MySQL, what is a class? What is an object? As far as I can tell, a class is spread out across the DB table it's data is stored in, and the individual script files that access and mutate that data.

With PHP 4 I know I can use OO features, but they do not really follow OO rules and are really just a different way or perceiving what is fundamentally a relational DB model.

What steps should I take to take my OOD of the system and design a technical specification, and develop it using PHP/MySQL (and HTML, CSS and JavaScript)?


----------------------------------------------------------------------------
The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
 
First, find some good books on OO - there are lots...

Now this is just scratching the surface, and is no substitue for a decent book, but here goes.

Start by identifying the core processes of your application, and decide what kind of object should be responsible. For instance, all your data-access functions can become part of a Data-Manager class (or group of clases) instead of your pages executing the sql directly. This buys you a layer of abstraction which gives you flexibility, maintainability, the potential for code-reuse and increases the clarity of your code in general.

Then you might identify business entity classes. For the primary entities anyway, there is often a 1:1 relationship between your database tables and business entity classes. So if you had a Customers table, you would have a Customer class with instances of Customer objects - one for each row. This gives you a strongly-typed interface between your objects, and further encapsulates the data and responsiblities which is a good thing.

Hope that helps.

[pipe]
 
PHP isn't object oriented... It's mainly a linear scripting language, not unlike ASP.
 
That's true I guess. I know that in PHP you can make your own classes with methods and members (not unlike vbscript) but you still have to "include" the code for the class whenever you want to use it, whereas in Java or .NET you can compile it and just reference it as needed. (right?) I think the other limitation of PHP classes is that there is no accessibility levels for the class members - everything is Public, which kind of breaks the OO principal. At least that's how it was when I last used it...



[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top