Re: [PW-dev] Static methods - was Widget factory
Status: Alpha
Brought to you by:
spadkins
From: Gunther B. <gu...@ex...> - 2001-06-12 15:00:16
|
At 09:49 AM 6/12/01 +0200, Issac Goldstand wrote: > > At 05:08 PM 6/11/2001 -0500, you wrote: > > >"Jay Lawrence" <Ja...@La...> wrote: > > >>James and Stephen, > > >> > > >>Could you please expand on what you mean by static methods? > > > > > >These would be methods that are not tied to an instance -- the `new' >method > > >(basically, any constructor) is an example of a usually static method. >Any > > >method that requires an instance of an object class is not a static >method. > > > > > >Perl blurs the line between static and non-static methods. C++ is very > > >explicit and requires the `static' keyword before the function >declaration. > > > > > >The static methods do not have an object to get any information from, so >any > > >configuration information they get would have to either come from the > > function > > >arguments or from globals. > > >-- > > >James Smith <JG...@TA...>, 979-862-3725 > > >Texas A&M CIS Operating Systems Group, Unix > > > > > > > James is correct on all points. > > For example > > > > $wc = Widget->controller(); > > > > is a "static" method on the Widget package. No instance of a "Widget" >class > > was required in order to call the controller() method. Any routine called > > from the package name (i.e. Package::Name->method_name()) is a static >method. > > (The terminology indeed comes from C++ and Java.) > > > > A "normal" method call (dynamic?) is called on an instance of a class. >i.e. > > > > $query = CGI->new(); # this is a static method call, called from > > package > > print $query->param("x"); # this is a normal (dynamic) method call, > > called from object > > > > The "Factory" pattern is a standard way of constructing objects without > > knowing > > what type of objects they actually are. In order to instantiate an >object, > > you > > normally need to know the class of the object. With a factory, you can >let > > the > > factory decide. In this way, > > > > $wc = Widget->controller(); > > > > is letting the static method, "controller()", in the Widget package decide > > which > > class it should instantiate when returning a Controller. > > Similarly, with > > > > $date_widget = $wc->widget("date"); > > > > we are letting the controller decide (based on config and runtime >information) > > what actual class to instantiate. > > > > Thus, both the Widget package and Widget::Controller objects are acting as > > factories > > in the PWL. > > > > Stephen > >Wait a second... I was under the impression that the Widget::COntroller >object simply got "bound" to a top level Widget object somewhere... That >you couldn't actually go about creating the actual Widgets until you had an >instantiated Controller.... Am I barking up wrong trees here??? I also think the controller should be instantiated. I plan on having a controller that is very different from the controller that I imagine the localization folks and other more powerful flexible feature people need to have while keeping the widgets simple. By the way, having static methods also is closely tied to the idea of a Singleton design pattern (which can be implemented as either a class static methods or as an instantiation that uses a static to realize it's already been instantiated once). |