From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 1AE7CBB83 for ; Fri, 5 May 2006 15:00:32 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k45D0VHt023367 for ; Fri, 5 May 2006 15:00:31 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA28146 for ; Fri, 5 May 2006 15:00:30 +0200 (MET DST) Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.179]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k45D0Ta6023355 for ; Fri, 5 May 2006 15:00:30 +0200 Received: by py-out-1112.google.com with SMTP id c59so783500pyc for ; Fri, 05 May 2006 06:00:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=N/sEq7lSWKoWBgwXWPL7O/FGpyZSKdOrdYUb4UTy/NMLXYRsIzYnBoUhwGR2nZKp+XNvAThk6JTUwRisM1FcD/6yGyOm57f5BMkQtR3ZKNH82KEVt304tdhWVebs5orauE0fP4vpXHToccp1F9n/impsgZe/Rg5Ci5V86jlgz4s= Received: by 10.35.112.3 with SMTP id p3mr95033pym; Fri, 05 May 2006 06:00:29 -0700 (PDT) Received: by 10.35.27.19 with HTTP; Fri, 5 May 2006 06:00:29 -0700 (PDT) Message-ID: <6b8a91420605050600g1d2e7ea9t2ee5e5df126819c6@mail.gmail.com> Date: Fri, 5 May 2006 15:00:29 +0200 From: "Remi Vanicat" To: david.baelde@ens-lyon.org Subject: Re: [Caml-list] OO design Cc: Ocaml In-Reply-To: <53c655920605050235k64e70333je8df813239ea3c53@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <53c655920605050235k64e70333je8df813239ea3c53@mail.gmail.com> X-j-chkmail-Score: MSGID : 445B4C6D.001 on concorde : j-chkmail score : X : 0/20 1 X-Miltered: at concorde with ID 445B4C6F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 445B4C6D.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; gerd:01 stolpmann:01 overriding:01 struct:01 foo:01 sig:01 foo:01 2006:98 caml-list:01 behaviour:01 remi:01 remi:01 vanicat:01 vanicat:01 unit:03 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 2006/5/5, David Baelde : > Hi, > > I'm no OO guru, so my question may be irrelevant, or there just might > not be an answer, which wouldn't hurt.. > > Let's say that I have a base class, with some kind of activation > procedure: anybody wanting to use the class must call #enter before, > and then call #leave for releasing. Internally, the methods #do_enter > and #do_leave are called respectively at the first #enter and last > #leave. > > Nobody should call the #do_* directly, and I'd also like to make sure > the #enter and #leave are never overriden, since their behaviour is > important and actually much more complex than what I said. If the solution given Gerd Stolpmann have the problem to disallow the inheritence, I've another that make ineritence and overriding enter and leave possible, but ensure that method that overide enter and leave do call the old enter and leave : struct type enter =3D unit type leave =3D unit class foo =3D method enter ... : enter =3D .... method leave ....: leave =3D ... .... end end : sig type enter type leave class foo : method enter : ... -> enter method leave : ... -> leave end end after this, the only way to produce an object of type enter is to call the original enter method (same for leave). And as method that overide enter must have the same type, the have to call the enter method to have it (well, there might be other way, but the user of the method have to make thing complicated for this). Another plus of this method of doing it is that if you haev e method of typ= e method bar : enter -> unit then one can only call it if he had call previously the enter method.