Skip to content

Commit

Permalink
renamed stuff to make use of the term DependencyInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhess committed Oct 18, 2009
1 parent 180f661 commit 96b343f
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 93 deletions.
11 changes: 4 additions & 7 deletions source/src/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<?xml version="1.0"?>
<componentPackage>
<component class="net.seanhess.zero.common.ZEventDispatcher"/>

<component class="net.seanhess.zero.context.Register"/>

<component class="net.seanhess.zero.interfaces.Implementation"/>
<component class="net.seanhess.zero.interfaces.Interface"/>
<component class="net.seanhess.zero.interfaces.InterfaceEvent"/>
<component class="net.seanhess.zero.common.DEventDispatcher"/>

<component class="net.seanhess.zero.dependency.Register"/>
<component class="net.seanhess.zero.dependency.DependencyInterface"/>
</componentPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package net.seanhess.zero.common
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import net.seanhess.zero.interfaces.Interface;

public class ZEventDispatcher extends Interface implements IEventDispatcher
import net.seanhess.zero.dependency.DependencyInterface;

public class DEventDispatcher extends DependencyInterface implements IEventDispatcher
{
public function ZEventDispatcher(context:*) { super(context) }
public function DEventDispatcher(context:*) { super(context) }

public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
import net.seanhess.zero.util.Invalidator;

Expand Down
10 changes: 10 additions & 0 deletions source/src/net/seanhess/zero/dependency/DependencyError.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package net.seanhess.zero.dependency
{
public class DependencyError extends Error
{
public function DependencyError(message:String)
{
super(message);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
import flash.events.Event;
import flash.events.IEventDispatcher;
import flash.utils.Dictionary;

import mx.core.IMXMLObject;

import net.seanhess.zero.context.Register;
import net.seanhess.zero.context.Utils;

/**
* The implementation will be
*/
public class Interface implements IMXMLObject
public class DependencyInterface implements IMXMLObject
{
protected var utils:Utils = new Utils();

Expand All @@ -27,7 +20,7 @@ package net.seanhess.zero.interfaces

protected var register:Register = new Register();

public function Interface(context:*=null)
public function DependencyInterface(context:*=null)
{
type = utils.getName(this);
setContext(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
/**
* Creates a new instance of the implementation every time it is needed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
/**
* Allows you to specify a full impelemntation, which matches up everything that matches
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
import flash.utils.Proxy;
import flash.utils.flash_proxy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.interfaces
package net.seanhess.zero.dependency
{
/**
* Allows you to wrap calls. Should allow you to do regular expressions in the match.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.context
package net.seanhess.zero.dependency
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
Expand All @@ -7,9 +7,6 @@ package net.seanhess.zero.context
import mx.collections.ArrayCollection;
import mx.collections.ListCollectionView;

import net.seanhess.zero.interfaces.Implementation;
import net.seanhess.zero.interfaces.InterfaceError;

public class Register
{
/**
Expand Down Expand Up @@ -51,11 +48,28 @@ package net.seanhess.zero.context

if (rules.length == 0)
{
throw new InterfaceError("Could not find implementation for " + type + " in context "+ context);
throw new DependencyError("Could not find implementation for " + type + " in context "+ context);
}

var rule:Rule = rules.getItemAt(rules.length-1) as Rule;
var instance:* = rule.factory.newInstance();

var instance:*;

if (rule.kind == Rule.IMPLEMENT)
{
if (cache[rule.factory] == null)
cache[rule.factory] = rule.factory.newInstance();

instance = cache[rule.factory];
}
else if (rule.kind == Rule.FACTORY)
{
instance = rule.factory.newInstance();
}
else
{
throw new Error("Rule not implemented");
}

var implementation:Implementation = new Implementation();
implementation.onlyImplementation = instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.context
package net.seanhess.zero.dependency
{
import mx.core.ClassFactory;
import mx.core.IFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.seanhess.zero.context
package net.seanhess.zero.dependency
{
import flash.utils.getQualifiedClassName;

Expand Down
10 changes: 0 additions & 10 deletions source/src/net/seanhess/zero/interfaces/InterfaceError.as

This file was deleted.

41 changes: 0 additions & 41 deletions source/src/net/seanhess/zero/interfaces/InterfaceEvent.as

This file was deleted.

4 changes: 2 additions & 2 deletions test/dev/src/dev/interfaces/IBook.as
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.interfaces
{
import net.seanhess.zero.interfaces.Interface;
import net.seanhess.zero.dependency.DependencyInterface;

public class IBook extends Interface
public class IBook extends DependencyInterface
{
public function IBook(context:*) { super(context) }

Expand Down
25 changes: 22 additions & 3 deletions test/dev/src/dev/interfaces/ILibrary.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,31 @@ package dev.interfaces
{
import mx.collections.IList;

import net.seanhess.zero.common.ZEventDispatcher;
import net.seanhess.zero.interfaces.Interface;
import net.seanhess.zero.dependency.DependencyInterface;


// it could be a Zinterface
// ha...

// or a Zero extends Zero

// because it isn't exactly an interface, is it. A new concept would be better
// ZSomething

// Zinterface
// Zecorator
// Decorator (because that's what it is)
// But it's acting like an interface, because it isn't doing anything.
// ZInterface
// zinterface
// zero
// extends ZeroDecorator
// public class ZLibrary extends ZeroDecorator
// public class ZLibrary
// public class DLibrary extends DependencyInterface // that's a nice touch. It is an interface to a dependency

[Event(name="newBook", type="flash.events.Event")]
public class ILibrary extends ZEventDispatcher
public class ILibrary extends DependencyInterface
{
public function ILibrary(context:*=null):void { super(context); }

Expand Down
2 changes: 1 addition & 1 deletion test/dev/src/dev/services/Library.as
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package dev.services
public function createBook(title:String):void
{
var book:IBook = new IBook(this);
book.title = title;
book.title = title + Math.random();


allBooks.addItem(book);
Expand Down
8 changes: 5 additions & 3 deletions test/dev/src/main.mxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import dev.services.Book;
import dev.services.Library;
import net.seanhess.zero.context.Register;
import net.seanhess.zero.context.Rule;
import net.seanhess.zero.dependency.Register;
import net.seanhess.zero.dependency.Rule;
Expand All @@ -26,7 +26,7 @@
private function init():void
{
register.addRule(new Rule(Rule.IMPLEMENT, Library, "dev.interfaces.ILibrary"));
register.addRule(new Rule(Rule.IMPLEMENT, Book, "dev.interfaces.IBook"));
register.addRule(new Rule(Rule.FACTORY, Book, "dev.interfaces.IBook"));
trace("HUH?");
library = new ILibrary(this);
Expand All @@ -35,6 +35,8 @@
});
}
private function asdf():void
{
library.createBook("new book");
Expand Down

0 comments on commit 96b343f

Please sign in to comment.