Re: My hang-up about OOP (snit)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: My hang-up about OOP (snit)
De : rich (at) *nospam* example.invalid (Rich)
Groupes : comp.lang.tcl
Date : 26. Jun 2024, 05:09:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5g49n$1vjk4$1@dont-email.me>
References : 1 2 3
User-Agent : tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Luc <luc@sep.invalid> wrote:
On Tue, 25 Jun 2024 22:29:46 -0000 (UTC), Rich wrote:
 
If you only *ever* have one dog, either are essentially the same.
>
But, if at some point you want to manage spot, frank, sam, donut, and
alexa, all of which are different dogs, then you can do:
>
   snit::type dog {
       method {tail wag}   {} {return "Wag, wag"}
       method {tail droop} {} {return "Droop, droop"}
   }
>
Once to create a generic "dog" framework.
>
And then later do, all in the same single program instance:
>
dog spot
dog frank
dog sam
dog donut
dog alexa
>
And have five, fully independent dogs (each with their own independent
"data") that you can manipulate, without having to do anything special
at the time you create them.
>
I.e., you can wag spot's tail, give food to sam, and label alexa with
"last vet visit was 2024-06-21" (assuming you had mentods for 'feed'
and for 'last-vet-visit' in the generic framework.
 
 
And how is that better than this:
 
proc dog {dogname args} {
        if {$args == "tail wag"}        {return "$dogname Wag, wag"}
        if {$args == "tail droop"}      {return "$dogname Droop, droop"}
        if {$args == "eats food"}       {return "$dogname Nom, nom"}
        if {$args == "goes to vet"}     {return "$dogname Tries to run"}
 
}
puts [dog fido tail wag]
puts [dog lucky tail droop] 
puts [dog charlie eats food]
puts [dog mitts goes to vet]
 
That will handle multiple dogs pretty well.
 
One "method," one "if." It's pretty much it, isn't it?

Also, Ashok's chapter from his Tcl book that describes 8.6's OO
subsystem is available online:

https://www.magicsplat.com/articles/oo.html

You might consider carefully reading it.  It is not that long, and
Ashok uses the "bank account" metaphor instead of the "dog" one, which
provides some intuitiveness into the "separate variables in each
object" aspect (you don't want your bank account data shared with
others you did not approve it to be shared with).


Date Sujet#  Auteur
25 Jun 24 * My hang-up about OOP (snit)22Luc
25 Jun 24 +* Re: My hang-up about OOP (snit)10Rich
25 Jun 24 i`* Re: My hang-up about OOP (snit)9Luc
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i `* Re: My hang-up about OOP (snit)5Rich
27 Jun 24 i  +* Re: My hang-up about OOP (snit)3Luc
27 Jun 24 i  i`* Re: My hang-up about OOP (snit)2Rich
27 Jun 24 i  i `- Re: My hang-up about OOP (snit)1Lawrence Woodman
27 Jun 24 i  `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 +- Re: My hang-up about OOP (snit)1saito
26 Jun 24 +* Re: My hang-up about OOP (snit)9Robert Heller
27 Jun 24 i`* Re: My hang-up about OOP (snit)8Luc
27 Jun 24 i `* Re: My hang-up about OOP (snit)7Robert Heller
27 Jun 24 i  `* Re: My hang-up about OOP (snit)6Luc
28 Jun 24 i   `* Re: My hang-up about OOP (snit)5Robert Heller
28 Jun 24 i    `* Re: My hang-up about OOP (snit)4Luc
28 Jun 24 i     `* Re: My hang-up about OOP (snit)3Robert Heller
28 Jun 24 i      `* Re: My hang-up about OOP (snit)2Luc
28 Jun 24 i       `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 `- Re: My hang-up about OOP (snit)1Luis Mendes

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal