package com.ericfeminella.utils
{
import mx.utils.StringUtil;
/**
*
* Abstract class which enforces a class of static type is never
* instantiated.
*
* <p>
* All static classes (classes which ONLY contain static members)
* are to extend AbstractStaticBase. Implementors need not provide
* any implementation. By extending AbstractStaticBase it will be
* ensured that a class instance can not e instantiated.
* </p>
*
* <p>
* Typically, Helper, Utility and Enumeration classes will extend
* AbstractStaticBase to ensure clients do not misuse an API by
* explicitly instantiating an instance of the static type
* </p>
*
* @example
* <listing version="3.0">
*
* package
* {
* public final class CalculationUtils extends AbstractStaticBase
* {
* public static function calculateX() : String {
* // implementation not relevant
* }
*
* public static function calculateY() : String {
* // implementation not relevant
* }
*
* public static function calculateZ() : String {
* // implementation not relevant
* }
* }
* }
*
* // an attempt to instantiate an instance of CalculationUtils...
*
* var util:CalculationUtils = new CalculationUtils();
*
* // results in the following exception being throw:
* // Illegal instantiation attempted on class of static type: CalculationUtils
*
* </listing>
*
*
*/
public class AbstractStaticBase
{
/**
* Defines the message String which is used as the property of the Exception
*/
private static const MESSAGE:String = "Illegal instantiation attempted on class of static type: {0}";
/**
*
* Determines the sub class which was instantiated and throws
* an error of specifying the class which was instantiated
*
*/
public function AbstractStaticBase()
{
var exception:Error = new Error();
var stackFrame:String = exception.getStackTrace().split("at ")[2];
var fullyQualifiedName:String = stackFrame.split("()")[0];
exception.message = StringUtil.substitute( MESSAGE, fullyQualifiedName );
throw exception;
}
}
}