Thread: Classes in PHP
View Single Post
  #7 (permalink)  
Old Oct 11th, 2007, 13:56
Rakuli's Avatar
Rakuli Rakuli is offline
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Classes in PHP

Quote:
Originally Posted by parms View Post
And something else I forgot to mention:

You have not explained how this would work relative to file structures, would the classes sit in different files and if so any particular area?

Would you have lots of classes for different things?

Would these class files then be incliuded at the top of my content php page?

Can you tell I am new to this??
A class can be anywhere, but it is convention (and helps in organisation) to have each class in its own file. You can have a class intermingled with your code but this sort of defeats the purpose.

Yes, you have many classes. Say one to deal with users and a class for products that lets you create an object for each product.

If you had an online shop, you could have a class that creates objects for each item. Each item has properties (price, name, availability) and methods (changePrice, checkAvailability).

Once you have set up the methods, you can call them and they take all of the processing out of the script that's outputting their data......

Ummmm.. an anolgy for OOP abstraction is this.

Your computer hardware is the base of your computer heirachy the next level up in this abstraction is the operating system kernel , then the hardware device drivers followed by applications running on your operating system.

When you write a computer program, it would be very hard to have to write the code to deal with the hardware primitives for everything. Instead, the program takes advantage of object libraries in the operating system (which in turn deals with the drivers objects that deal with the hardware) allowing the end program to just asks for those results.

This is why programs generally cannot be used on different operating systems as they are tapping into the objects set up for a given system. The program doesn't have to worry about the fiddly bits and can just use the results of the abstraction to perform its functions.

I hope I am making sense. OOP doesn't allow you to do anything more than what you can do normally, it just allows you to do it in a more ergonomical, logical way.

It's a way of mind

*** Rakulie stops himself before saying "very good grasshopper" ***

Last edited by Rakuli; Oct 13th, 2007 at 23:15.
Reply With Quote