Archive for the ‘Design Patterns’ Category

Links: Design Patterns

May 27, 2010
  1. Structural Patterns – Facade Patternhides the complexities of system from the client and provides a simpler interface, see there as well
    (list of patterns as in book “Design Patterns, Elements of Reusable Object Oriented Software” by E.Gamma, R.Helm, R.Johnson, J.Vlissides):

    1. Creational Patterns:
      1. Factory Pattern
      2. Abstract Factory Pattern
      3. Singleton Pattern
      4. Builder Pattern
      5. Prototype Pattern
    2. Structural Patterns:
      1. Adapter Pattern
      2. Bridge Pattern
      3. Composite Pattern
      4. Decorator Pattern
      5. Facade Pattern
      6. Flyweight Pattern
      7. Proxy Pattern
    3. Behavioral Patterns:
      1. Chain of Responsibility Pattern
      2. Command Pattern
      3. Interpreter Pattern
      4. Iterator Pattern
      5. Mediator Pattern
      6. Momento Pattern
      7. Observer Pattern
      8. State Pattern
      9. Strategy Pattern
      10. Template Pattern
      11. Visitor Pattern
  2. Entry-Point Function Definition: Microsoft DLL
  3. QueryInterface retrieves pointers to the supported interfaces on an object

Design Patterns: Singleton

May 21, 2010

1). Implementation from Scott Morgan: (ExternalInterfaceBuffer source code)

package …
public class ExternalInterfaceBuffer{

private static var instance:ExternalInterfaceBuffer = new ExternalInterfaceBuffer();
public function ExternalInterfaceBuffer() {
if( instance ) throw new Error( “Singleton and can only be accessed through Singleton.getInstance()” );
}

public static function getInstance():ExternalInterfaceBuffer {
return instance;
}

2). from Darron Schall: Actionscript 3 Singleton Redux

package …

private static const _instance:Model = new Model( SingletonLock )
public function Model( lock:Class )
{
// Verify that the lock is the correct class reference.
if ( lock != SingletonLock ){
throw new Error( “Invalid Singleton access.  Use Model.instance.” );
}
}

class SingletonLock{} // end class

3). Grant Skinner: AS3 Singleton

4). What if you would like to pass some arguments in constructor?

Links: Definitions

May 17, 2010
  1. Hash tables (hush function), “to quickly locate a data record (for example, a dictionary definition) given its “search key
    Associative arrays, dynamic sets.
  2. Namespaces: tutorial from Grant Skinner
  3. Matrices in AS3: tutorial from Senocular
  4. Matrix: analog of  “MovieClip.localToGlobal(point)” on Matrix level:

import flash.geom.Matrix;
/**
 * "Global" matrix of nested MovieClip
 * @author Sergei Nikiforovski, 2010
 * note: as2 !
 */
public function getMc_nestedMatrix( mc:MovieClip ):Matrix
 {
 var m0:Matrix = mc.transform.matrix;

 var mc2:MovieClip;
 var m:Matrix = new Matrix();

 for (var s in mc) {
 if ( typeof( mc[s] ) == "movieclip" ) {
 mc2 = mc[s];
 m = getMc_nestedMatrix( mc2 );
 break;
 }
 }

 m.concat( m0 );
 return m;
 }