My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package org.as3lib.utils
{
import org.as3lib.utils.strictIs;
import org.as3lib.errors.AbstractError;

/**
* A utility class for helping to enforce runtime Abstract class and
* method checking.
*
* @author Mims Wright
*/
public class AbstractEnforcer
{
/**
* When called within a constructor, ensures that the constructor
* cannot be instantiated unless it is subclassed.
*
* @param self A reference to the object whose constructor is being called.
* @param abstractClass The class to make abstract. The class of the constructed object.
* @throws org.as3lib.errors.AbstractError If self is an instance of abstractClass (and not a subclass).
*
* @example
* <listing version="3.0">
* package {
* public class AbstractClass {
* // this constructor cannot be called (without throwing an error) unless AbstractClass is subclassed.
* public function AbstractClass() {
* AbstractEnforcer.enforceConstructor(this, AbstractClass);
* // other constructor code here.
* }
* }
* }
* </listing>
*/
public static function enforceConstructor(self:Object, abstractClass:Class):void {
if (strictIs(self, abstractClass)) {
throw (new AbstractError(AbstractError.CONSTRUCTOR_ERROR));
}
}

/**
* When called within a method, will throw an error if the method is
* called, thus forcing it to be overridden in a subclass to be used.
* Note, there can be no default implementation of an abstract method so
* using super.methodName() will still throw the error.
*
* @throws org.as3lib.errors.AbstractError If the method is called without being overridden.
*
* @example <listing version="3.0">
* package {
* public class AbstractClass {
* // this method must be overridden.
* public function abstractMethod() {
* AbstractEnforcer.enforceMethod();
* }
* }
* }
* </listing>
*/
public static function enforceMethod ():void {
throw (new AbstractError(AbstractError.METHOD_ERROR));
}
}
}
Show details Hide details

Change log

r30 by mimshwright on Oct 27, 2009   Diff
Replaced @use with @example in ASDocs and
made sure all examples were rendered in
the documentation.
Go to: 
Project members, sign in to write a code review

Older revisions

r18 by mimshwright on Aug 16, 2009   Diff
Refactored AbstractEnforcer.
Added test case for AbstractEnforcer.
r3 by mimshwright on Nov 29, 2007   Diff
move files to trunk. oops.
r2 by mimshwright on Nov 29, 2007   Diff
added src and bin
All revisions of this file

File info

Size: 2121 bytes, 64 lines

File properties

svn:executable
*
Hosted by Google Code