abstract(n)

πŸ“¦
version 9.0.3 Β· 3 versions
, in alpine 3.23, alpine 3.24, nixos 26.05

✨ abstract(n) β€” the TclOO commands glow-up ✨

okay bestie, this one's from TclOO, and it's literally the manual page for oo::abstract. yes the whole page. no we're not skipping anything πŸ’…


🌸 NAME 🌸

oo::abstract β€” a class that does not allow direct instances of itself 🫢


⭐ SYNOPSIS ⭐

package require tcl::oo

oo::abstract method ?arg ...?

πŸ¦‹ CLASS HIERARCHY πŸ¦‹

like, the family tree. the ancestry. the bloodline πŸ‘‘

oo::object
   β†’ oo::class
       β†’ oo::abstract

πŸ’– DESCRIPTION πŸ’–

so abstract classes are classes that can totally contain definitions, but you can't directly manufacture them, bestie β€” no cap. they're intended to only ever be inherited from and instantiated indirectly. it's giving "i don't do solo careers, i only do features" energy ✨

the characteristic methods of oo::class (create and new) are not exported by an instance of oo::abstract. so yeah, you can't just roll up and new one. that's the whole point πŸ™ˆ

ngl, a plot twist: oo::abstract is not itself an instance of oo::abstract. iconic. the rule doesn't apply to the rule-maker πŸ’€

πŸŽ€ CONSTRUCTOR πŸŽ€

the oo::abstract class does not define an explicit constructor. which means it's effectively the same as the constructor of the oo::class class. lowkey just vibing with the default πŸ’œ

🧚 DESTRUCTOR 🧚

the oo::abstract class does not define an explicit destructor either. destroying an instance of it is just like destroying an ordinary class β€” and heads up, it will destroy all its subclasses too. transitive destruction, periodt. the whole family goes down together 😭

πŸ”₯ EXPORTED METHODS πŸ”₯

the oo::abstract class defines no new exported methods. zero. none. empty list, main character energy 🌈

πŸ’€ NON-EXPORTED METHODS πŸ’€

the oo::abstract class explicitly states that create, createWithNamespace, and new are unexported. so they're right there in the forbidden section, iykyk 🚫


πŸ“ EXAMPLES πŸ“

this example defines a simple class hierarchy and creates a new instance of it. then it invokes a method of the object before destroying the hierarchy and showing that the destruction is transitive. fr fr, watch:

oo::abstract create fruit {
    method eat {} {
        puts "yummy!"
    }
}
oo::class create banana {
    superclass fruit
    method peel {} {
        puts "skin now off"
    }
}
set b [banana new]
$b peel              β†’ prints 'skin now off'
$b eat               β†’ prints 'yummy!'
set f [fruit new]    β†’ error 'unknown method "new"...'

so banana ate and slayed because it inherited from the abstract fruit πŸ’… but trying to new the abstract fruit directly? error. unknown method "new".... we love a boundary 🌸


🌈 SEE ALSO 🌈

  • oo::define(n)
  • oo::object(n)

πŸ‘‘ KEYWORDS πŸ‘‘

abstract class, class, metaclass, object


and that's the whole page, bestie πŸ’– this one's TclOO version 0.3, page abstract(n) β€” go forth and inherit responsibly πŸ§šβ€β™€οΈβœ¨

πŸ“¦ where this page comes from