(* -----------------------------------------*)
(*  objectf.nb  March 2013    Richard Hall *)
(* -----------------------------------------*)

(*
   The object f has a function and parameters. It also    has methods which fetch and change the parameter values. 
Notice  =  rather than  :=  in the definition of f[] 
Thus the local parameters are not  reset to 1 each time f is called; f remembers their current values.
Switch is like If with more choices.
The strange numbers occur after the definition because
 at the start a and b are not initialized.
*)

f[ci_,x_] = Module[{a=1,b=1},Switch[ci,1, Exp[-a x]*Sin[b x], 
                       2, a=x, 3, b=x,4,a,5,b,
                      6,"Exp[-a x]*Sin[b x]"]]

(* Nowe se define the methods of f  *)

ff[x_] := f[1,x]

fgeta :=f[4,1]

fgetb := f[5,1]

fgetf := f[6,1]

fseta[a_] :=f[2,a]

fsetb[b_] := f[3,b]

(* We test the methods  *)

fgetf

ff[1]

fgeta

fseta[0.4]

fgeta

fsetb[6]

Plot[ff[x],{x,0,5}]

(* In spite of the  parameter machinery, ff behaves like a function  *)

Plot[ff'[x],{x,0,5}]