473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Best way of calling multiple classes?

I'm designing a small framework with a lot of classes (1 file per class) and
want to know the best method of calling each class?

Obviously I could I call each file that is used but that could be 10 or more
include statements. I am wonering if there is a better way? It's bit
annoying you can't build packages like Java.

Cheers

Phil
Aug 28 '07 #1
11 1613
Phil Latio wrote:
I'm designing a small framework with a lot of classes (1 file per class)
and want to know the best method of calling each class?

Obviously I could I call each file that is used but that could be 10 or
more include statements. I am wonering if there is a better way? It's bit
annoying you can't build packages like Java.
RTFM about __autoload().

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/
Proudly running Debian Linux with 2.6.22-1-amd64 kernel, KDE 3.5.7, and PHP
5.2.3-1+b1 generating this signature.
Uptime: 01:52:55 up 7 days, 22:13, 5 users, load average: 0.28, 0.31, 0.43

Aug 28 '07 #2
Phil Latio wrote:
I'm designing a small framework with a lot of classes (1 file per class) and
want to know the best method of calling each class?

Obviously I could I call each file that is used but that could be 10 or more
include statements. I am wonering if there is a better way? It's bit
annoying you can't build packages like Java.

Cheers

Phil

I just put in the include statements.

Actually, I don't use include - I use require_once. And if a class
depends on another class (often in my case), the require_once goes in
the requiring file.

That way the main file only needs to worry about what it needs, as each
file takes care of its own includes.

__autoload is good - but it requires extra processing over and above a
require_once, and pretty much everything has to reside in the same
directory.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 29 '07 #3
RTFM about __autoload().

Thank you, I most certainly will.

Cheers

Phil
Aug 29 '07 #4
..oO(Jerry Stuckle)
>__autoload is good - but it requires extra processing over and above a
require_once, and pretty much everything has to reside in the same
directory.
My __autoload() invokes a special class loader method, which allows to
store all my classes and interfaces in subdirectories. The class loader
is able to recursively search through the tree structure if necessary.
The exact location of each found class is cached in an index file, so
the overhead for loading a class is quite small.

Micha
Aug 29 '07 #5
Michael Fesser wrote:
.oO(Jerry Stuckle)
>__autoload is good - but it requires extra processing over and above a
require_once, and pretty much everything has to reside in the same
directory.

My __autoload() invokes a special class loader method, which allows to
store all my classes and interfaces in subdirectories. The class loader
is able to recursively search through the tree structure if necessary.
The exact location of each found class is cached in an index file, so
the overhead for loading a class is quite small.

Micha
Not bad. But it also adds complexity and overhead.

Don't get me wrong - I like __autoload. But I also like to keep things
simple. Make for much easier troubleshooting in six months.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 29 '07 #6
..oO(Jerry Stuckle)
>Not bad. But it also adds complexity and overhead.
Yep, but it pays off for me. I profile my code from time to time and the
real bottlenecks are always somewhere else.
>Don't get me wrong - I like __autoload. But I also like to keep things
simple. Make for much easier troubleshooting in six months.
Point taken, but for me it has real advantages. My entire framework has
become rather complex and is still growing. I also have to change the
directory structure from time to time to clean things up (there are
still some ugly things left from the early days of that class library,
which have to be improved). So it makes things a lot easier if I can let
the library perform some rather common tasks automatically.

A while ago I also thought about something like an import() function,
which could have worked like the 'import' statement in Java:

import('/path/to/classes/TFoo'); // load a single class
import('/path/to/classes/*'); // load all classes in that directory

But then PHP 5 and __autoload() came up ...

Another interesting approach I once saw (IIRC in the Prado framework,
but I'm not sure) was something like the import() above, but the
function didn't load the classes, but just added the supplied path to
PHP's include_path. Then the class could easily require_once all other
required classes without having to worry about the directory structure.

Micha
Aug 29 '07 #7

"Michael Fesser" <ne*****@gmx.dewrote in message
news:ct********************************@4ax.com...
.oO(Jerry Stuckle)
>>__autoload is good - but it requires extra processing over and above a
require_once, and pretty much everything has to reside in the same
directory.

My __autoload() invokes a special class loader method, which allows to
store all my classes and interfaces in subdirectories. The class loader
is able to recursively search through the tree structure if necessary.
The exact location of each found class is cached in an index file, so
the overhead for loading a class is quite small.
Did you write this yourself did you download it from somewhere? Sounds like
just what I am after.

Cheers

Phil
Aug 29 '07 #8
On Aug 29, 4:06 am, gosha bine <stereof...@gmail.comwrote:
>
autoload is rather a dirty hack and as such should be avoided.
Why do so many people say this? autoload does exactly what it was
intended to do and it works perfectly. It solved a major problem that
people had complained about for a long time. Would you care to
elaborate on your objections to using it?

Aug 29 '07 #9
ZeldorBlat wrote:
On Aug 29, 4:06 am, gosha bine <stereof...@gmail.comwrote:
>autoload is rather a dirty hack and as such should be avoided.

Why do so many people say this? autoload does exactly what it was
intended to do and it works perfectly. It solved a major problem that
people had complained about for a long time. Would you care to
elaborate on your objections to using it?
autoload is a "magic quotes"-type of solution to me: it attempts to
solve the real problem, but at the wrong place and in the wrong way.
Besides that, it's "magic" (which stinks like hell) and it's global
(which stinks even more).

We don't need yet another stinky "magic" quick fix in php. We do need a
decent packaging system and the catchable ClassNotFound exception.
--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Aug 29 '07 #10
gosha bine wrote:
autoload is a "magic quotes"-type of solution to me: it attempts to
solve the real problem, but at the wrong place and in the wrong way.
Besides that, it's "magic" (which stinks like hell) and it's global
(which stinks even more).

We don't need yet another stinky "magic" quick fix in php. We do need a
decent packaging system and the catchable ClassNotFound exception.
I gotta say - that whole "magic" thing really turns me off. I'm sure
someone somewhere has good use for it - but as an engineering type, I
get real nervous when folks start naming their algorithms after concepts
from fantasy novels.

I just seems so... deprecable.

(And if I see one more security server named "gandalf", I swear to God
I'll put on a suicide vest and blow the damned thing up myself. - Just
kidding - hahahaha.)
Aug 29 '07 #11
..oO(gosha bine)
>autoload is a "magic quotes"-type of solution to me: it attempts to
solve the real problem, but at the wrong place and in the wrong way.
Besides that, it's "magic" (which stinks like hell)
__set(), __get(), __call() ... all "magic", but very useful from time to
time. If you don't like them, simply don't use them.

Micha
Aug 29 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Martin Maney | last post by:
I've been to the cookbook (both forms, since they're sometimes usefully different), but that gave rise to more questions than answers. Heck, let me pull some of them up while I'm at it. ...
14
by: Axel Straschil | last post by:
Hello! Im working with new (object) classes and normaly call init of ther motherclass with callin super(...), workes fine. No, I've got a case with multiple inherance and want to ask if this...
3
by: Sasha | last post by:
Hi everybody, I would like to hear your thoughts on the following problem. We have the following classes. Class Exam int ID* int Version* string Name
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
12
by: Perre Van Wilrijk | last post by:
Hi there, When I started using VB6, I used to write classes with properties and functions as following ... Private lngf1 As Long Private strf2 As String Public Property Get f1() As Long...
12
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL...
3
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hi, I have been developing using C# in ASP.Net for about a year now. And have been a programmer for about 10 years. I have learned many different things in .NET, but still when I look at sample...
1
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
The code below is pretty simple. Calling Talker() in the parent returns "Parent", and calling Talker() in the child returns "Child". I'm wondering how I can modify the code so that a call to the...
7
by: Ashutosh Bhawasinka | last post by:
Hi, I have a C# .Net application which needs to use some feature which can be only developed in Visual C++ (its extended MAPI). The C# exe will be supplied to users without a setup. What kind...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.