Browse thread
initialization of instance variables
-
John Whitley
-
Jerome Vouillon
-
John Whitley
- Hendrik Tews
-
John Whitley
-
Jerome Vouillon
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Hendrik Tews <tews@i...> |
| Subject: | Re: initialization of instance variables |
John Whitley writes:
While the let-bound version works, it seems to obfuscate the intent,
which was to have an instance variable called 'x'. It also means that
a subclass inheriting foo' cannot reuse or redefine x.
I have two remarks about that:
1. IMO the intent of your example is that a complicated function
is computed just before object creation. I think this is best
captured by the let construction. Alternatively you could use
initializers and exploit late binding in the computation of the
complicated function.
2. You can still have an instance variable x:
(* make initial computation _very_ explicit *)
class foo' input =
let x_init = complicated_function input in
let y_init = another function x_init in
object
val x = x_init
val y = y_init
(* those imaginary methods again... *)
end
Bye,
Hendrik