views:

67

answers:

3

Hi all,

I devlopp web applications with Zend Framework.

For now, I have a huge library, wich contains each an every things, used by a couple of web applications. I am thinking of reorganising it, using the concept of "Module".

But I am not sure about the difference between Module and Package.

What I understand is :

  • a Module contains a part of a web application (pages, models...)
  • a Package is a group of class in the library

Am I seeing it right ? And how to know where should go my classes (model of a module, or library) ?

Because for example, I have some classes to do the translations. I have "model" classes, to represent a language, a text and its traductions... And I have kind of an "API" class that is just here to translate a string into a language. I would say that I need a module for the model classes and the web interface to edit the traductions, and the API class would go in the library ? Is that right ? Isn't that weird to have 2 kind of classes, one for the module and one for the library.

I guess that's an open question about API, librairie and application architecture.

A: 

packages are namespace areas so that symbols with similar names do not clash with one another. For example, the symbol &main::first is different from symbol &List::Util::first . Packages are name prefixes to sysbols.

A module is a file of code, or a tree of bytecodes. A module could be precompiled (.pmc), uncompiled (.pm) on disk; or pre-loaded in memory as one unit -- assuming no autosplit.

In summary: packages are about namespaces, and modules are about files. They are different things, like apples and boxes -- until the day when you start placing one kind of apple into one kind of box, and people start thinking that apples and boxes are related. And they are! but still, one in fruit and the other is a type of container.

streetparade
That's not what *modules* are in ZF terms.
Gordon
yep Gordon, you're right I am talking about ZF modules
Matthieu
+2  A: 

Modules, in the ZF sense, group concrete, often standalone, application parts:

Modules allow a developer to group a set of related controllers into a logically organized group. The structure under the modules directory would resemble the structure under the application directory. […] The directory structure for modules should mimic that of the application/ directory in the recommended project structure

A package on the other hand is a set of classes in a code library that conceptually belong together. For instance, ActionHelpers and ControllerPlugins conceptually belong to the Zend_Controller package. All available Validator classes belong to the package Zend_Validate.

When using PHPDocumentor you can annotate your code to belong to packages. If you look at ZF's API Docs, you will see this grouping in effect. Try to find the Zend_Validate_Alpha class.

See

Gordon
A: 

Simple in my view:
Modules are like smarty (a library with a targeted goal templating).
Packages are 2 or more modules that work with each other to offer a more complete solution.
Again my simple point of view.

DCC