Browse thread
[Caml-list] Five Questions about Objects
[
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: | Oleg <oleg_inconnu@m...> |
| Subject: | Re: [Caml-list] Five Questions about Objects |
On Sunday 14 July 2002 11:47 am, Xavier Leroy wrote:
> > 2) What is the point of "class" and "new" keywords? How are they better
> > than "let" ? E.g.
> >
> > let point a b =
> > object
> > val x = a
> > val y = b
> > method get () = (x, y)
> > end;;
> >
> > let my_point = point 3 7;;
> > let many_float_points = Array.make 100 (point 4.0 3.0);;
> > ?
>
> The main purpose of the class system is to support inheritance and
> method overriding. Object-oriented programming comes in two flavors:
> class-based OOP, which is what all mainstream OO languages offer, and
> delegation-based OOP, where there are no classes, objects are built
> directly by listing their fields and methods like you suggested, and
> method overriding is performed directly on objects, e.g. via a "copy
> this object, replacing these methods" operation. While there have
> been some theoretical work on delegation-based OOP, I think it is fair
> to say that it is less well understood than class-based OOP.
I thought my suggestion had to do with syntax only. One could still write
things like
type color = Red | Green | Blue
let pixel a b (c:color) =
object
inherit point a b as p
val col = c
method get_color () = col
method get_coords () = p#get ()
end
I don't really see any significant "OO flavor" difference, just simpler and
more consistent syntax IMHO: two keywords are eliminated, and class
definition is now just function definition. If that is not the case, can you
give examples in current O'Caml syntax that do not translate well into this
"syntax" ?
Thanks
Oleg
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners