Re: My hang-up about OOP (snit)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: My hang-up about OOP (snit)
De : luc (at) *nospam* sep.invalid (Luc)
Groupes : comp.lang.tcl
Date : 25. Jun 2024, 23:57:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240625195730.26db3755@lud1.home>
References : 1 2
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?

--
Luc
>


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