472,958 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 1593
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.