<HTML> <HEAD> <TITLE>How do I design my own classes?</TITLE> </HEAD> <BODY> <P><B>Links</B>: <A HREF=bugs.html>Next</A> <A HREF=example.html>Previous</A> <A HREF=sgmlspm.html>Up</A> <A HREF=sgmlspm.html>Top</A></P> <H1>How do I design my <EM>own</EM> classes?</H1> <P>In addition to the methods listed above, all of the classes used in <A HREF=sgmlspm.html><TT>SGMLS.pm</TT></A> have an <TT>ext</TT> method which returns a reference to an initially-empty hash table. You are free to use this hash table to store <EM>anything</EM> you want -- it should be especially useful if you are building your own, derived classes from the ones provided here. The following example builds a derived class <TT>My_Element</TT> from the <A HREF=sgmlselement.html><TT>SGMLS_Element</TT></A> class, adding methods to set and get the current font:</P> <P> <PRE>use SGMLS; package My_Element; @ISA = qw(SGMLS_Element); sub new { my ($class,$element,$font) = @_; $element->ext->{'font'} = $font; return bless $element; } sub get_font { my ($self) = @_; return $self->ext->{'font'}; } sub set_font { my ($self,$font) = @_; $self->ext->{'font'} = $font; }</PRE> </P> <P>Note that the derived class does not need to have any knowledge about the underlying structure of the <A HREF=sgmlselement.html><TT>SGMLS_Element</TT></A> class, and need only avoid shadowing any of the methods currently existing there.</P> <P>If you decide to create a derived class from the <A HREF=sgmls.html><TT>SGMLS</TT></A>, please note that in addition to the methods listed above, that class uses internal methods named <TT>element</TT>, <TT>line</TT>, and <TT>file</TT>, similar to the same methods in <A HREF=sgmlsevent.html><TT>SGMLS_Event</TT></A> -- it is essential that you not shadow these method names.</P> <P><B>Links</B>: <A HREF=bugs.html>Next</A> <A HREF=example.html>Previous</A> <A HREF=sgmlspm.html>Up</A> <A HREF=sgmlspm.html>Top</A></P> <ADDRESS>David Megginson <A HREF="mailto:dmeggins@aix1.uottawa.ca"><dmeggins@aix1.uottawa.ca></A></ADDRESS> </BODY> </HTML>