class



class

NAME
SYNOPSIS
CLASS HIERARCHY
DESCRIPTION
EXAMPLES
SEE ALSO
KEYWORDS

___________________________

NAME

oo::class − class of all classes

SYNOPSIS

package require TclOO

oo::class method ?arg ...?

CLASS HIERARCHY

oo::object
oo::class ___________________________

DESCRIPTION

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’s factory methods, typically either create if an explicit name is being given, or new if an arbitrary unique name is to be automatically selected.

The oo::class 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 oo::object, so every class is also an object. Additional metaclasses (i.e., classes of classes) can be defined if necessary by subclassing oo::class. Note that the oo::class object hides the new method on itself, so new classes should always be made using the create method.

CONSTRUCTOR
The constructor of the oo::class class takes an optional argument which, if present, is sent to the oo::define command (along with the name of the newly-created class) to allow the class to be conveniently configured at creation time.

DESTRUCTOR
The oo::class 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.

EXPORTED METHODS
cls
create name ?arg ...?

This creates a new instance of the class cls called name (which is resolved within the calling context’s namespace if not fully qualified), passing the arguments, arg ..., 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.

cls new ?arg ...?

This creates a new instance of the class cls with a new unique name, passing the arguments, arg ..., 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.

Note that this method is not exported by the oo::class object itself, so classes should not be created using this method.

NON-EXPORTED METHODS
The oo::class class supports the following non-exported methods:
cls
createWithNamespace name nsName ?arg ...?

This creates a new instance of the class cls called name (which is resolved within the calling context’s namespace if not fully qualified), passing the arguments, arg ..., 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’s internal namespace will be nsName 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.

EXAMPLES

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.

oo::class create fruit {
method eat {} {
puts "yummy!"
}
}
oo::class create
banana {
superclass fruit
constructor {} {
my variable peeled
set peeled 0
}
method peel {} {
my variable peeled
set peeled 1
puts "skin now off"
}
method edible? {} {
my variable peeled
return $peeled
}
method eat {} {
if {![my edible?]} {
my peel
}
next
}
}
set b [banana new]
$b eat → prints "skin now off" and "yummy!"
fruit destroy
$b eat → error "unknown command"

SEE ALSO

oo::define(n), oo::object(n)

KEYWORDS

class, metaclass, object




More Linux Commands

manpages/y4mtoppm.1.html
y4mtoppm(1) - Convert YUV4MPEG2 stream to PPM images........
y4mtoppm converts a YUV4MPEG2 stream into a sequence of raw PPM images. Output is to stdout (but feel free to have the shell redirect to a file). Input is read

manpages/ati.4.html
ati(4) - ATI video driver (Special files - Linux man page)
ati is an Xorg wrapper driver for ATI video cards. It autodetects whether your hardware has a Radeon, Rage 128, or Mach64 or earlier class of chipset, and loads

manpages/fgetgrent_r.3.html
fgetgrent_r(3) - get group file entry reentrantly (ManPage)
The functions getgrent_r() and fgetgrent_r() are the reentrant versions of getgrent(3) and fgetgrent(3). The former reads the next group entry from the stream i

manpages/virtual.8.html
virtual(8) - Postfix virtual domain mail delivery agent.....
The virtual(8) delivery agent is designed for virtual mail hosting services. Originally based on the Postfix local(8) delivery agent, this agent looks up recipi

manpages/intro3.html
intro(3) - Introduction to library functions (Man Page).....
Section 3 of the manual describes all library functions excluding the library functions (system call wrappers) described in Section 2, which implement system ca

manpages/resize_term_sp.3ncurses.html
resize_term_sp(3ncurses) - curses screen-pointer extension
This implementation can be configured to provide a set of functions which improve the ability to manage multiple screens. This feature can be added to any of th

manpages/xdr_enum.3.html
xdr_enum(3) - library routines for external data representat
These routines allow C programmers to describe arbitrary data structures in a machine-independent fashion. Data for remote procedure calls are transmitted using

manpages/ausyscall.8.html
ausyscall(8) a program that allows mapping syscall names and
ausyscall is a program that prints out the mapping from syscall name to number and reverse for the given arch. The arch can be anything returned by uname -m. If

manpages/opaque.3ncurses.html
opaque(3ncurses) - curses window properties - Linux man page
This implementation provides functions which return properties set in the WINDOW structure, allowing it to be opaque if the symbol NCURSES_OPAQUE is defined: is

manpages/wenclose.3ncurses.html
wenclose(3ncurses) - mouse interface through curses.........
These functions provide an interface to mouse events from ncurses(3NCURSES). Mouse events are represented by KEY_MOUSE pseudo-key values in the wgetch input str

manpages/XRRQueryExtension.3.html
XRRQueryExtension(3) - X Resize, Rotate and Reflection exten
Xrandr is a simple library designed to interface the X Resize and Rotate Extension. This allows clients to change the size and rotation of the root window of a

manpages/Tcl_RegisterConfig.3.html
Tcl_RegisterConfig(3) - procedures to register embedded conf
The function described here has its base in TIP 59 and provides extensions with support for the embedding of configuration information into their binary library





We can't live, work or learn in freedom unless the software we use is free.