How does OOP manage to 'include' classes stored in different files?

The technology answer is PHP Autoloading The implementation answer is this: One common method used has to do with the names of classes relating to folder structure. There are articles out there, but here is a brief summary: When setting up your autoload code, take the class name and replace underscores with slashes. This way you can organize your classes in folders For example: Classname: Database_Provider_MySQL File: Database/Provider/MySQL.

Php So in autoload, you'd take the incoming classname, replace the underscores with slashes. Then include that specific file This achieves what you are trying to accomplish, you can simply load a class by creating a new instance of it. You never have to use the include statement for these classes Do remember to not go to deep where you end up with 6+ levels.

I think between 3 and 5 is a good maximum Also, this does require that you keep only 1 class per file (similar to Java). Though it might seem inconvenient, it makes locating code a lot easier.

The technology answer is PHP Autoloading. The implementation answer is this: One common method used has to do with the names of classes relating to folder structure. There are articles out there, but here is a brief summary: When setting up your autoload code, take the class name and replace underscores with slashes.

This way you can organize your classes in folders. For example: Classname: Database_Provider_MySQL File: Database/Provider/MySQL. Php So in autoload, you'd take the incoming classname, replace the underscores with slashes.

Then include that specific file. This achieves what you are trying to accomplish, you can simply load a class by creating a new instance of it. You never have to use the include statement for these classes.Do remember to not go to deep where you end up with 6+ levels.

I think between 3 and 5 is a good maximum. Also, this does require that you keep only 1 class per file (similar to Java). Though it might seem inconvenient, it makes locating code a lot easier.

1 Searching foar few terms in this reply I found a pretty decent tutorial brainbell. Com/tutorials/php/TOC_oop. Html – wheresrhys Apr 25 '09 at 22:33.

PHP has functionality to automatically load files based on some call you make. PHP: Autoloading Objects is your definitive resources on the matter.

Different languages/frameworks do it different ways, but it essential boils down to there's a built-in list of default locations to look and/or you can specify where to look (how you do this again depends on language/framework). I know the question is tagged as php but the question doesn't specifically mention php so thought I'd give a slightly more general answer.

I have one remark, although I am huge (understatement) fan of PHP (down vote me all you want, I don't care! One day we will be accepted ;-), PHP is not really the path you want to walk down when learning OOP. PHP does things, well, different.

Different is good, don't get me wrong, I love different, but it is also unconventional. Unconventional, also good, almost a synonym for Google, if you ask me, but we do not live in an unconventional world! You can not just walk up to somebody and say; " I know OOP, I learned it in PHP".

It may rhyme, but people just won't take you seriously afterwards. Don't ask me why, but it is as true as yellow bananas. I've been there.So if you want to learn conventional OOP, try Java.

It's as conventional as they come (which is neither bad nor good). I have honestly never backed myself up so many times in a 20-sentence post. Gotta watch ma' rep though.

:-D.

I've found it extremely helpful to look at existing code when my research efforts hit a wall. There are plenty of scripts, packages, frameworks, and applications that follow excellent PHP coding practices that can be studied and learned from. There have been several questions on SO that point out a couple good ones.My favorite so far have been the Zend Framework.

PHP's include_path configuration setting tells PHP what directories to look in for files. If you do something like this: Then PHP searches the current directory for 'MyClass. Php' and then searches any directories on the include_path if it can't find the file.

Many class libraries do something like this: It can be further simplified with auto-loading: us.php.net/autoload Other libraries just include every file the use right off the bat in the base package file, so all those classes are available immediately.

And on a related note, if anyone can recommend a good book or online tutorial which will provide a good foundation in OOP (preferably php based) I'd be very grateful. Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development.

What you're describing has nothing to do with object-oriented programming per se. It's just a feature of certain specific languages. Those languages do it by enforcing some sort of convention for how files are stored (for example, the class foo.bar.

Quux might have to be in some standard location at foo/bar/quux. Py).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions