Re: [PHP] class? package?
Shelley wrote: I am working on a sns site, and now my practice is grouping classes of a function classes of a function... perhaps classes related to certain functionality? (i. e. subscription) together. When I need it, just load the package: subscription. Right? ;) Hm... I do not know your project, but to have many classes just to handle subscription, sounds a bit too much to me. Why don't you have a class called subscription, which might even extend a class called person or user - the subscription class can have methods, for instance subscribe and unsubscribe, and because subscription extends person or user - it already knows who is the person/user. And then, for example, to subscribe a person/user, you do - $subscription-subscribe($list_id); Other possible actions - $subscription-un_subscribe($list_id); $subscription-is_subscriber($list_id); $subscription-lists(); etc. This way class subscription packs the methods needed to handle subscription related activities, so in your own jargon, this class is a package. Of course, if the subscription process is extremely complicated, you can have more classes. Iv -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class? package?
Shelley wrote: Probably you have noticed this: The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all. If that's the case, then why not just use one class as one package? What's the point of splitting a package into several classes? :-( I think somebody already answered. It is actually up to you. My grandmother used to write letters starting with a capital letter, writing the whole letter as one long sentence and ending with a dot. This would perhaps confuse most high school teachers, but in her case it somehow worked :) If we take this worn out example - if you have a class dog and a class cat - it becomes quite clear why you need several classes. You can put them in a package called animals - but as other people already noted, the packages in php have only a symbolic role, just for clarity of code organization. Iv -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class? package?
On Wed, Jun 11, 2008 at 12:02 PM, Larry Garfield [EMAIL PROTECTED] wrote: On Tuesday 10 June 2008, Shelley wrote: Hi all, If you are designing with OO principles, could you give an explanation of what is the difference classes and packages? Several principles talks about classes and packages, such as: The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all. but few explains the difference between them. When I was summarizing the OO principles, that question confused me: http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles- of-object-oriented-design Thanks in advance. :) A class is a syntactic way of grouping behavior and data together in an encapsulated fashion (at least that's the PHP definition). A formal package is a syntactic way of grouping related classes together, either for easier distribution, somewhat tighter coupling, or syntactic sugar. For instance, you could have 5 classes that make up your Database abstraction package; they're all discrete, but all work in concert. PHP does not have a syntactic package concept. The closest thing would be namespaces as implemented in PHP 5.3, but that's not out yet. Many systems emulate packages with verbose class naming (eg, Database_Connection, Database_Query, Database_Transaction, Database_Query_Select, etc.), but I personally find that ugly. :-) Thank you very much for the explanation. I think I got some. Maybe I am already using them: I am working on a sns site, and now my practice is grouping classes of a function (i.e. subscription) together. When I need it, just load the package: subscription. Right? ;) -- Regards, Shelley
Re: [PHP] class? package?
On Thu, Jun 12, 2008 at 3:01 PM, Iv Ray [EMAIL PROTECTED] wrote: Shelley wrote: Probably you have noticed this: The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all. If that's the case, then why not just use one class as one package? What's the point of splitting a package into several classes? :-( I think somebody already answered. It is actually up to you. My grandmother used to write letters starting with a capital letter, writing the whole letter as one long sentence and ending with a dot. This would perhaps confuse most high school teachers, but in her case it somehow worked :) If we take this worn out example - if you have a class dog and a class cat - it becomes quite clear why you need several classes. You can put them in a package called animals - but as other people already noted, the packages in php have only a symbolic role, just for clarity of code organization. Yeah, that's it. -- Regards, Shel
Re: [PHP] class? package?
If you are designing with OO principles, could you give an explanation of what is the difference classes and packages? A class is a language construct, classes are processed/executed by php. A package is an architectural approach - this is how you combine your code/classes. When I was summarizing the OO principles, that question confused me: http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles-of-object-oriented-design If you try to follow all these principles, it might take very long before you write even a line of code ;) Take what you understand and leave the rest for later. You will become better, but will never be perfect ;) Iv -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class? package?
On Tue, Jun 10, 2008 at 6:32 PM, Iv Ray [EMAIL PROTECTED] wrote: If you are designing with OO principles, could you give an explanation of what is the difference classes and packages? A class is a language construct, classes are processed/executed by php. A package is an architectural approach - this is how you combine your code/classes. Yeah, I can guess that. Probably you have noticed this: The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all. If that's the case, then why not just use one class as one package? What's the point of splitting a package into several classes? :-( When I was summarizing the OO principles, that question confused me: http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles-of-object-oriented-design If you try to follow all these principles, it might take very long before you write even a line of code ;) True. Take what you understand and leave the rest for later. You will become better, but will never be perfect ;) You will never be perfect, but you will become better. ;) Iv -- Thank you any way. -- Regards, Shelley
RE: [PHP] class? package?
[snip] If that's the case, then why not just use one class as one package? What's the point of splitting a package into several classes? :-( [/snip] First of all think of what a class is and what it is meant to represent. Secondly think of a package in literal sense...a package can hold one or more items. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class? package?
On Wed, Jun 11, 2008 at 12:02 AM, Larry Garfield [EMAIL PROTECTED] wrote: On Tuesday 10 June 2008, Shelley wrote: Hi all, If you are designing with OO principles, could you give an explanation of what is the difference classes and packages? Several principles talks about classes and packages, such as: The classes in a package are reused together. If you reuse one of the classes in a package, you reuse them all. but few explains the difference between them. When I was summarizing the OO principles, that question confused me: http://phparch.cn/index.php/php/43-php-advanced-programming/170-principles- of-object-oriented-design Thanks in advance. :) A class is a syntactic way of grouping behavior and data together in an encapsulated fashion (at least that's the PHP definition). A formal package is a syntactic way of grouping related classes together, either for easier distribution, somewhat tighter coupling, or syntactic sugar. For instance, you could have 5 classes that make up your Database abstraction package; they're all discrete, but all work in concert. PHP does not have a syntactic package concept. The closest thing would be namespaces as implemented in PHP 5.3, but that's not out yet. Many systems emulate packages with verbose class naming (eg, Database_Connection, Database_Query, Database_Transaction, Database_Query_Select, etc.), but I personally find that ugly. :-) furthermore, in languages such as java (and likely others) packages have access levels which are conceptually similar to ppp in classes. this allows designers to limit access to certain classes in a given package (duh); it turns out to be quite useful. imagine you are a library author and some of the classes you distribute, you dont intend for your clients to use, well then, you simply mark those classes as private. i dont believe the php namespace concept incorporates this feature, nor do i think its really relevant, in a source based language. however, i do find it relevant to the discussion ;D -nathan