1itcl(n)                           [incr Tcl]                           itcl(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       itcl - object-oriented extensions to Tcl
9______________________________________________________________________________
10
11

DESCRIPTION

13       [incr Tcl] provides object-oriented extensions to Tcl, much as C++ pro‐
14       vides object-oriented extensions to C.  The emphasis of this work, how‐
15       ever, is not to create a whiz-bang object-oriented programming environ‐
16       ment.  Rather, it is to support more structured  programming  practices
17       in Tcl without changing the flavor of the language.  More than anything
18       else, [incr Tcl] provides a means of encapsulating  related  procedures
19       together  with their shared data in a namespace that is hidden from the
20       outside world.  It  encourages  better  programming  by  promoting  the
21       object-oriented  "library"  mindset.   It  also  allows for code re-use
22       through inheritance.
23
24

CLASSES

26       The fundamental construct in [incr Tcl] is the class definition.   Each
27       class  acts as a template for actual objects that can be created.  Each
28       object has its own unique bundle of data, which contains  instances  of
29       the "variables" defined in the class.  Special procedures called "meth‐
30       ods" are used to manipulate individual objects.  Methods are just  like
31       the  operations  that  are used to manipulate Tk widgets.  The "button"
32       widget, for example, has methods such  as  "flash"  and  "invoke"  that
33       cause a particular button to blink and invoke its command.
34
35       Within  the  body of a method, the "variables" defined in the class are
36       automatically available.  They need not be declared with anything  like
37       the  global  command.   Within  another  class  method, a method can be
38       invoked like any other command-simply by  using  its  name.   From  any
39       other  context,  the  method  name  must be prefaced by an object name,
40       which provides a context for the data that the method can access.
41
42       Each class has its own namespace containing things that are  common  to
43       all objects which belong to the class.  For example, "common" data mem‐
44       bers are shared by all objects in the class.  They are global variables
45       that  exist  in the class namespace, but since they are included in the
46       class definition, they need not be declared using the  global  command;
47       they  are  automatically  available  to any code executing in the class
48       context.  A class can also create ordinary global variables, but  these
49       must be declared using the global command each time they are used.
50
51       Classes  can also have ordinary procedures declared as "procs".  Within
52       another class method or proc, a proc can be invoked like any other com‐
53       mand-simply  by  using its name.  From any other context, the procedure
54       name  should  be  qualified  with  the  class  namespace  like  "class‐
55       Name::proc".   Class  procs execute in the class context, and therefore
56       have automatic access to all "common" data members.  However, they can‐
57       not  access object-specific "variables", since they are invoked without
58       reference to any specific object.  They are  usually  used  to  perform
59       generic operations which affect all objects belonging to the class.
60
61       Each  of  the elements in a class can be declared "public", "protected"
62       or "private".  Public elements can be accessed by the class, by derived
63       classes  (other  classes  that  inherit  this  class),  and by external
64       clients that use the class.  Protected elements can be accessed by  the
65       class, and by derived classes.  Private elements are only accessible in
66       the class where they are defined.
67
68       The "public" elements within a class define its interface to the exter‐
69       nal  world.   Public  methods define the operations that can be used to
70       manipulate an object.  Public variables are recognized as configuration
71       options  by the "configure" and "cget" methods that are built into each
72       class.  The public interface says what an object will do but not how it
73       will  do  it.   Protected and private members, along with the bodies of
74       class methods and procs, provide the implementation details.   Insulat‐
75       ing  the  application  developer  from  these  details leaves the class
76       designer free to change them at any time, without warning, and  without
77       affecting programs that rely on the class.  It is precisely this encap‐
78       sulation that makes object-oriented programs easier to  understand  and
79       maintain.
80
81       The  fact  that [incr Tcl] objects look like Tk widgets is no accident.
82       [incr Tcl] was designed this way, to  blend  naturally  into  a  Tcl/Tk
83       application.   But [incr Tcl] extends the Tk paradigm from being merely
84       object-based to being fully object-oriented.  An object-oriented system
85       supports  inheritance,  allowing  classes  to share common behaviors by
86       inheriting them from an ancestor or base class.  Having a base class as
87       a  common abstraction allows a programmer to treat related classes in a
88       similar manner.  For example, a toaster and a blender perform different
89       (specialized) functions, but both share the abstraction of being appli‐
90       ances.  By abstracting common behaviors into a base class, code can  be
91       shared  rather  than  copied.   The  resulting application is easier to
92       understand and maintain, and derived classes (e.g., specialized  appli‐
93       ances) can be added or removed more easily.
94
95       This  description  was  merely a brief overview of object-oriented pro‐
96       gramming and [incr Tcl].  A more tutorial introduction is presented  in
97       the  paper  included with this distribution.  See the class command for
98       more details on creating and using classes.
99
100

NAMESPACES

102       [incr Tcl] now includes a complete namespace facility.  A namespace  is
103       a  collection  of commands and global variables that is kept apart from
104       the usual global scope.  This allows Tcl code libraries to be  packaged
105       in a well-defined manner, and prevents unwanted interactions with other
106       libraries.  A namespace can also have child namespaces  within  it,  so
107       one  library  can contain its own private copy of many other libraries.
108       A namespace can also be used to wrap up a  group  of  related  classes.
109       The global scope (named "::") is the root namespace for an interpreter;
110       all other namespaces are contained within it.
111
112       See the namespace command for details on creating and using namespaces.
113
114

MEGA-WIDGETS

116       Mega-widgets are high-level widgets that are constructed using Tk  wid‐
117       gets  as component parts, usually without any C code.  A fileselection‐
118       box, for example, may have a few listboxes, some entry widgets and some
119       control  buttons.   These  individual widgets are put together in a way
120       that makes them act like one big widget.
121
122       [incr Tk] is a framework for building mega-widgets.  It uses [incr Tcl]
123       to  support  the  object  paradigm, and adds base classes which provide
124       default widget behaviors.  See the itk man page for more details.
125
126       [incr Widgets] is a library of mega-widgets built using [incr Tk].   It
127       contains  more  than 30 different widget classes that can be used right
128       out of the box to build Tcl/Tk applications.  Each widget class has its
129       own man page describing the features available.
130
131

KEYWORDS

133       class, object, object-oriented, namespace, mega-widget
134
135
136
137itcl                                  3.0                              itcl(n)
Impressum