{"id":5955,"date":"2022-12-20T18:57:46","date_gmt":"2022-12-20T21:57:46","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/class-mann\/"},"modified":"2022-12-20T18:57:46","modified_gmt":"2022-12-20T21:57:46","slug":"class-mann","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/class-mann\/","title":{"rendered":"class (mann)"},"content":{"rendered":"<h1 align=\"center\">class<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#CLASS HIERARCHY\">CLASS HIERARCHY<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#KEYWORDS\">KEYWORDS<\/a> <\/p>\n<hr>\n<p>______________________________________________________________________________<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">oo::class \u2212 class of all classes<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">package require TclOO<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>oo::class<\/b> <i>method<\/i> ?<i>arg &#8230;<\/i>?<\/p>\n<h2>CLASS HIERARCHY <a name=\"CLASS HIERARCHY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>oo::object<\/b> <br \/> \u2192 <b>oo::class<\/b> ______________________________________________________________________________<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Classes are objects that can manufacture other objects according to a pattern stored in the factory object (the class). An instance of the class is created by calling one of the class\u2019s factory methods, typically either <b>create<\/b> if an explicit name is being given, or <b>new<\/b> if an arbitrary unique name is to be automatically selected.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>oo::class<\/b> class is the class of all classes; every class is an instance of this class, which is consequently an instance of itself. This class is a subclass of <b>oo::object<\/b>, so every class is also an object. Additional metaclasses (i.e., classes of classes) can be defined if necessary by subclassing <b>oo::class<\/b>. Note that the <b>oo::class<\/b> object hides the <b>new<\/b> method on itself, so new classes should always be made using the <b>create<\/b> method.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>CONSTRUCTOR<\/b> <br \/> The constructor of the <b>oo::class<\/b> class takes an optional argument which, if present, is sent to the <b>oo::define<\/b> command (along with the name of the newly-created class) to allow the class to be conveniently configured at creation time.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>DESTRUCTOR<\/b> <br \/> The <b>oo::class<\/b> class does not define an explicit destructor. However, when a class is destroyed, all its subclasses and instances are also destroyed, along with all objects that it has been mixed into.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>EXPORTED METHODS<\/b> <i><br \/> cls<\/i> <b>create<\/b> <i>name<\/i> ?<i>arg &#8230;<\/i>?<\/p>\n<p style=\"margin-left:22%;\">This creates a new instance of the class <i>cls<\/i> called <i>name<\/i> (which is resolved within the calling context\u2019s namespace if not fully qualified), passing the arguments, <i>arg &#8230;<\/i>, to the constructor, and (if that returns a successful result) returning the fully qualified name of the created object (the result of the constructor is ignored). If the constructor fails (i.e. returns a non-OK result) then the object is destroyed and the error message is the result of this method call.<\/p>\n<p style=\"margin-left:11%;\"><i>cls<\/i> <b>new<\/b> ?<i>arg &#8230;<\/i>?<\/p>\n<p style=\"margin-left:22%;\">This creates a new instance of the class <i>cls<\/i> with a new unique name, passing the arguments, <i>arg &#8230;<\/i>, to the constructor, and (if that returns a successful result) returning the fully qualified name of the created object (the result of the constructor is ignored). If the constructor fails (i.e., returns a non-OK result) then the object is destroyed and the error message is the result of this method call.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\">Note that this method is not exported by the <b>oo::class<\/b> object itself, so classes should not be created using this method.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>NON-EXPORTED METHODS<\/b> <br \/> The <b>oo::class<\/b> class supports the following non-exported methods: <i><br \/> cls<\/i> <b>createWithNamespace<\/b> <i>name nsName<\/i> ?<i>arg &#8230;<\/i>?<\/p>\n<p style=\"margin-left:22%;\">This creates a new instance of the class <i>cls<\/i> called <i>name<\/i> (which is resolved within the calling context\u2019s namespace if not fully qualified), passing the arguments, <i>arg &#8230;<\/i>, to the constructor, and (if that returns a successful result) returning the fully qualified name of the created object (the result of the constructor is ignored). The name of the instance\u2019s internal namespace will be <i>nsName<\/i> unless that namespace already exists (when an arbitrary name will be chosen instead). If the constructor fails (i.e., returns a non-OK result) then the object is destroyed and the error message is the result of this method call.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This example defines a simple class hierarchy and creates a new instance of it. It then invokes a method of the object before destroying the hierarchy and showing that the destruction is transitive.<\/p>\n<p style=\"margin-left:22%; margin-top: 1em\"><b>oo::class create<\/b> fruit { <br \/> method eat {} { <br \/> puts &#8220;yummy!&#8221; <br \/> } <br \/> } <b><br \/> oo::class create<\/b> banana { <br \/> superclass fruit <br \/> constructor {} { <br \/> my variable peeled <br \/> set peeled 0 <br \/> } <br \/> method peel {} { <br \/> my variable peeled <br \/> set peeled 1 <br \/> puts &#8220;skin now off&#8221; <br \/> } <br \/> method edible? {} { <br \/> my variable peeled <br \/> return $peeled <br \/> } <br \/> method eat {} { <br \/> if {![my edible?]} { <br \/> my peel <br \/> } <br \/> next <br \/> } <br \/> } <br \/> set b [banana <b>new<\/b>] <br \/> $b eat <i>\u2192 prints &#8220;skin now off&#8221; and &#8220;yummy!&#8221;<\/i> <br \/> fruit destroy <br \/> $b eat <i>\u2192 error &#8220;unknown command&#8221;<\/i><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">oo::define(n), oo::object(n)<\/p>\n<h2>KEYWORDS <a name=\"KEYWORDS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">class, metaclass, object<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  oo::class \u2212 class of all classes <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3783,1],"tags":[2635,2648],"class_list":["post-5955","post","type-post","status-publish","format-standard","hentry","category-n-comandos-tcl-tk","category-sin-categoria","tag-mann","tag-oo_class"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=5955"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/5955\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=5955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=5955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=5955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}