Chapter Contents |
Previous |
Next |
SAS Component Language: Reference |
Relationships among Classes |
Classes that you define with SCL can support two types of relationships:
Class Ancestry
Whenever you create a new class, that class inherits
all of the properties (attributes, methods, events, event handlers, and interfaces)
that belong to its parent class. For example, the Object class is the parent
of all classes in SAS/AF software.
The Frame and Widget classes are subclasses of the Object class, and they
inherit all properties of the Object class. Similarly, every class you use
in a frame-based application is a descendent of the Frame, Object, or Widget
class, and thus inherits all the properties that belong to those classes.
All classes are instances of the Class class. The Class class is a metaclass. A metaclass collects information about other classes and enables you to operate on other classes. For more information about metaclasses, see Metaclasses.
Types of Classes |
Some SAS/AF software classes are specific types of classes.
The Widget class in SAS/AF software
is an example of an abstract class. Its purpose is to collect properties that
all widget subclasses can inherit. The Widget class cannot be instantiated.
Models are non-visual components that provide data. For example, a Data Set List model contains the properties for generating a list of SAS data sets (or tables), given a specific SAS library. A model may be attached to multiple views.
Views are components that provide a visual representation of the data, but they have no knowledge of the actual data they are displaying. The displayed data depends on the state of the model that is connected to the view. A view can be attached to only one model at a time.
It may be helpful to think of model/view components as client/server components. The view acts as the client and the model acts as the server.
For more information on interfaces, see Interfaces. For more information
on implementing model/view communication, refer to
SAS Guide to Applications Development and to the SAS/AF online
Help.
Metaclasses enable you to make changes to the application at run time rather than only at build time. Examples of such changes include where a class's methods reside, the default values of class properties, and even the set of classes and their hierarchy.
Metaclasses also enable you to access information about parent classes, subclasses, and the methods and properties that are defined for a class. Specifically, through methods of the Class class, you can
For more information about metaclasses, see the Class class in the SAS/AF online Help.
Defining Classes |
<ABSTRACT> CLASS class-name<EXTENDS
parent-class-name> <SUPPORTS supports-interface-clause> <REQUIRES requires-interface-clause> < / (class-optional-clause)> <(attribute-statements)> <(method-declaration-statements)> <(method-implementation-blocks)> <(event-declaration-statements)> <(eventhandler-declaration-statements)> |
ENDCLASS; |
The EXTENDS clause specifies the parent class. If you do not specify
an EXTENDS clause, SCL assumes that sashelp.fsp.object.class
is the parent class.
Using the CLASS block instead of the Class Editor to create a class enables the compiler to detect errors at compile time, which results in improved performance during run time.
For a complete description of the CLASS statement, see CLASS. For a
description of
using the Class Editor to define classes, refer to
SAS Guide to Applications Development.
class Simple extends myParent; public num num1; M1: method n:num return=num / (scl='work.a.uSimple.scl'); M2: method return=num; num1 = 3; dcl num n = M1(num1); return (n); endmethod; endclass;To generate a CLASS entry from the CLASS block, issue the SAVECLASS command or select
File | Save as class... |
File | Save as class... |
n=M1();You do not need to use the _SELF_ system variable:
n=_SELF_.M1();Omitting references to the _SELF_ variable (which is referred to as shortcut syntax) makes programs easier to read and maintain. However, if you are referencing a method or attribute that is not in the class you are creating, you must specify the object reference.
Instantiating Classes |
dcl mylib.classes.collection.class C1; C1 = _new_ Collection();You can combine these two operations as follows:
dcl mylib.classes.collection.class C1 = _new_ Collection();The _NEW_ operator combines the actions of the LOADCLASS function, which loads a class, with the _new method, which initializes the object by invoking the object's _init method.
You can combine the _NEW_ operator with the IMPORT statement, which defines a search path for references to CLASS entries, so that you can refer to these entries with one or two-level names instead of having to use a four-level name in each reference.
For example, you can use the following statements to
create a new collection object called C1 as an instance of the collection
class that is stored in mylib.classes.collection.class
:
/* Collection class is defined in */ /* the catalog MYLIB.MYCAT */ import mylib.mycat.collection.class; /* Create object C1 from a collection class */ /* defined in MYLIB.MYCAT.COLLECTION.CLASS */ declare Collection C1=_new_ Collection();
For more information, see _NEW_ and LOADCLASS.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.