Hi, it's not what I really want. I have a session class, in the init method depending on property I create a storageObj like this: namespace eval oodz { nx::Class create Session { :property {persist_type "file"}
# Constructor :method init {} { set :dom_sess [ns_info server]_sessions_cl ns_cache_create -timeout ${:timeout} -expires ${:session_expire} ${:dom_sess} 10MB switch ${:persist_type} { "file" { set :storageObj [::oodz::SessionFile new] } "db" { set :storageObj [::oodz::SessionDB new] } default { error "Unsupported storage type: ${:persist_type}" } } } After that i can access it like: ${:storageObj} save $sessionId $data
Basically I want something like *Factory Method* pattern. What is happening right now is that I am initializing my Session class. It works fine but after some time I'm getting an error that ${:storageObj} doesnt exist. In your example I need to know my type of the class before. Sorry, maybe I understood wrong. If you have a simple example of illustrating factory method I would be grateful. Thank you
On Tue, Sep 12, 2023 at 7:02 AM Stefan Sobernig stefan.sobernig@wu.ac.at wrote:
Hi Maksym!
I would recommend using a "property", watch:
package req nx
nx::Class create a { :public method hmmm {} { return "Hmmmm!!!" } } nx::Class create b { :property -accessor public aObj:object,type=::a
:public method saysmth {} { puts "Hello!? [${:aObj} hmmm]" }
}
# in init.tcl / created once ::b create bobj
# somewhere else (later):
::bobj aObj set [::a new] ::bobj saysmth
What do you think?
HTH, Stefan
Hello, can I use parameters to keep Class objects? Like this:
package require nx
nx::Class create a { :public method hmmm {} { return "Hmmmm!!!" } }
nx::Class create b { :method init {} { set :aObj [a new] }
:public method saysmth {} { puts "Hello!? [${:aObj} hmmm]" } }
::b create bobj ::bobj saysmth
Is it possible that it will not be set if I create my "bobj" from
init.tcl
in Naviserver at startup?
Thank you in advance _______________________________________________ Xotcl mailing list Xotcl@alice.wu.ac.at http://alice.wu.ac.at/mailman/listinfo/xotcl
Xotcl mailing list Xotcl@alice.wu.ac.at http://alice.wu.ac.at/mailman/listinfo/xotcl