Thread: Re: [PW-dev] Static methods - was Widget factory
Status: Alpha
Brought to you by:
spadkins
From: James G S. <JG...@TA...> - 2001-06-11 22:05:42
|
"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 |
From: Stephen A. <ste...@of...> - 2001-06-12 03:01:08
|
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 |
From: Issac G. <ne...@wr...> - 2001-06-12 10:27:34
|
> 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??? Issac Internet is a wonderful mechanism for making a fool of yourself in front of a very large audience. --Anonymous Moving the mouse won't get you into trouble... Clicking it might. --Anonymous PGP Key 0xE0FA561B - Fingerprint: 7E18 C018 D623 A57B 7F37 D902 8C84 7675 E0FA 561B |
From: Stephen A. <ste...@of...> - 2001-06-12 11:19:38
|
At 09:49 AM 6/12/2001 +0200, you wrote: >> At 05:08 PM 6/11/2001 -0500, you wrote: >> >"Jay Lawrence" <Ja...@La...> wrote: ... >> 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??? > > Issac The Widget::Controller is a controller, not a widget. For more info on what a "controller" is, please see the FAQ. http://www.officevision.com/pub/Widget/FAQ.html The API is currently set up to require you to instantiate a Controller before you can successfully instantiate any widgets because it is through the Controller that you have access to configuration and state information. If one of the desired usage variants is to instantiate widgets *directly*, there would need to be a default global Controller created. This brings us back to our Teambuilding Exercise #2: Usage ... Q. Do we need to be able to do the following? (I think this is what Jay is implying.) use Widget::HTML::Button; $button = Widget::HTML::Button->new ( -name => "fetch", -bgcolor => "#ff0000", ); I had intended that this *not* be valid usage because of the globals it would require. Rather that all widgets be instantiated via the Controller like so. use Widget; $wc = Widget->controller(); $button = $wc->widget ( -name => "fetch", '-widget-class' => "Widget::HTML::Button", -bgcolor => "#ff0000", ); Stephen |
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). |