Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Best way to 'add modules' to web app?

by chunlou (Curate)
on Jul 05, 2003 at 16:19 UTC ( #271647=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Best way to 'add modules' to web app?
in thread Best way to 'add modules' to web app?

The problem sounds more like a functional programming one (where you focus on evaluating "expression")than OOP one. I don't think inheritance (though it might not what you really meant) it's necessarily good for customization and even less for flexibility. It leads to too tight a coupling.

OOP is a good way to deal with design time customization. At runtime, or so you could think, it's another story. Think about a calculator. It evaluates arbitrary expression at runtime. It all depends on how you model the problem and/or your spec.

As to how one might conceptualize overriding a sub, I might think of a sub a value in a hash with rules determining which key (and therefore sub) to pick, either at runtime or design time. Think about this (trivial) example:
sub make_binary { eval "sub { $_[0] }" } my %op ; $op{add} = make_binary '$_[0] + $_[1]' ; $op{sub} = make_binary '$_[0] - $_[1]' ; $op{mul} = make_binary '$_[0] * $_[1]' ; $op{div} = make_binary '$_[0] / $_[1]' ; $op{max} = make_binary '$_[0] > $_[1] ? $_[0] : $_[1]' ; for (sort keys %op) { print "2 $_ 3 = " . $op{$_}->(2,3) . "\n"; }
Kind of customization via "templating."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://271647]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2017-12-17 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (462 votes). Check out past polls.

    Notices?