Re: Class method or Object method?

2009-01-29 Thread Mark Hedges
On Thu, 29 Jan 2009, David Ihnen wrote: > > I have encountered this 'back call into execution context' a few times. > Generally to me this means you have a singleton pattern. > > In a short concise code expression: > > package Cart; > my $instance; > sub new { return $instance ||= bless {}, $self

Re: Class method or Object method?

2009-01-29 Thread David Ihnen
kropotkin wrote: Hi Steven Not quite. From the catalogue I want to see what is in the user's cart. As they browse the catalogue they will see a flag next to each item if it is in the basket; 'n already in your basket' sort of thing. So from the class which produces catalogue pages I want to be

Re: Class method or Object method?

2009-01-29 Thread kropotkin
Hi Steven Not quite. From the catalogue I want to see what is in the user's cart. As they browse the catalogue they will see a flag next to each item if it is in the basket; 'n already in your basket' sort of thing. So from the class which produces catalogue pages I want to be able to obtain in

Re: Class method or Object method?

2009-01-29 Thread Steven Siebert
> > > This isn't quite informative. But objects also make it easier >> to inter-relate a bunch of methods that you haven't necessarily >> programmed yet without having to remember what arguments you >> have to pass around from method to method, because you can get >> them out of $self when you nee

Re: Class method or Object method?

2009-01-29 Thread Mark Hedges
> the next request. Objects are useful because they form > discrete containers of data in the blessed references that > represent unique entities of a particular class, and they > (typically) would not persist across requests unless you use > a persistent object storage mechanism that keeps them

Re: Class method or Object method?

2009-01-29 Thread Mark Hedges
On Thu, 29 Jan 2009, Steven Siebert wrote: > On Thu, Jan 29, 2009 at 2:11 PM, kropotkin wrote: > > class A is the Catalogue and B is the Cart. Usually they > > are separate but I want to show a flag relating to the > > basket/cart in the catalogue against each product. > > Really I am putting th

Re: Class method or Object method?

2009-01-29 Thread David Nicol
in general, doing gymnastics to support IS-A syntax when you have a HAS-A semantic is ill-advised. On Thu, Jan 29, 2009 at 11:54 AM, kropotkin wrote: > > Hi > > In general is it better to use a class method or object method? E.g I have a > class A which provides certain functionality. I just want

Re: Class method or Object method?

2009-01-29 Thread kropotkin
Throw a dog a bone... Michael Peters wrote: > > kropotkin wrote: > >> In general is it better to use a class method or object method? > > It depends on what you're using it for and how. Does the method act on any > instance specific state > data? Or does it act on class specific data? >

Re: Class method or Object method?

2009-01-29 Thread Steven Siebert
If I am reading your situation correctly, you want to be able to reference the catalogue for product information from the cart? If this is the case, perhaps the cart should be a container for "PurchaseItem" objects which contain the essential data (ie price, weight) and behaviours (calcShippingCos

Re: Class method or Object method?

2009-01-29 Thread Mark Hedges
On Thu, 29 Jan 2009, Marilyn Burgess wrote: > I really like this example too, though it lacks a class > method example: > > if(DOG::number_of_dogs_in_the_pound() > 1){ >     foreach my $dog (@Pound){ >     if($dog->is_male()){ >     print "I though so"; >     } >     } > } > > Sor

Re: Class method or Object method?

2009-01-29 Thread kropotkin
Hi Steven The method doesn't effect the state of anything . It just returns some information. The context is: class A is the Catalogue and B is the Cart. Usually they are separate but I want to show a flag relating to the basket/cart in the catalogue against each product. Really I am putting the

Re: Class method or Object method?

2009-01-29 Thread Marilyn Burgess
I really like this example too, though it lacks a class method example: if(DOG::number_of_dogs_in_the_pound() > 1){ foreach my $dog (@Pound){ if($dog->is_male()){ print "I though so"; } } } Sorry, I couldn't resist after that female comment. Marilyn On Thu, J

Re: Class method or Object method?

2009-01-29 Thread kropotkin
Hi My class doesn't poop. period. Michael Peters wrote: > > kropotkin wrote: > >> In general is it better to use a class method or object method? > > It depends on what you're using it for and how. Does the method act on any > instance specific state > data? Or does it act on class specifi

Re: Class method or Object method?

2009-01-29 Thread André Warnier
Michael Peters wrote: kropotkin wrote: In general is it better to use a class method or object method? It depends on what you're using it for and how. Does the method act on any instance specific state data? Or does it act on class specific data? A more concrete example would be a Dog clas

Re: Class method or Object method?

2009-01-29 Thread Steven Siebert
It depends. (always the expected answer with an OOP design question =) Generally, if the method you are calling on class A does not work on/effect the state of a specific object, its a canidate to be a static (class) method. However, you should be careful about coupling your objects and understan

Re: Class method or Object method?

2009-01-29 Thread Michael Peters
kropotkin wrote: In general is it better to use a class method or object method? It depends on what you're using it for and how. Does the method act on any instance specific state data? Or does it act on class specific data? A more concrete example would be a Dog class. Is bark() a method o

Class method or Object method?

2009-01-29 Thread kropotkin
Hi In general is it better to use a class method or object method? E.g I have a class A which provides certain functionality. I just want to use one of its methods in another class B. Is it better to inistantiate class A and do and object call or just do A->myMethod() ? The method doesn't need a