To follow on with Composition...
Heres a Concept i'd like to float past you and see if this
affects anyones thoughts.
Take a config file within mach-II (just built this concept
for DRK 10 app i wrote).
it basically has the following
Filters,
Listeners
Pageviews
Plugins
Properties
EventHandlers
- notify (links to
Listeners)
- viewpage (links to
PageViews)
- filter (links to Filters)
- parameters
etc..
From an OO perspective, i've built a concept that has
this:
collectionObject
FilterObject
ListenerObject
PageViewObject
PluginObject
PropertyObject
EventHandlerObject
ConfigObject
ConfigObject:
- filterCollectionManager = new
collectionObject()
- listenerCollectionManager = new
collectionObject();
etc..
instance.collections = new
Struct();
instance.collections.filters =
ArrayNew(1);
// Pass in a Listener Object and sequence pos
(optional).
createListener( oListener:ListenerObject,
sequence:int ) {
instance.collections.listeners =
listenerCollectionManager.addItemAt(sequence, oLisetner.getName(),
oListener);
}
createEventHandler(oEventHandler:EventHandlerObject,
sequence) {
// 1) Check to make sure all notify
elements have actual listeners within this config to link to, store errors in a
stack.
var aNotifications =
oEventHandler.getAllNotifications();
var stNotifyResults =
validateNotifications(aNotifications);
etc...
if(Success) {
instance.collections.eventhandlers =
EventHandlerCollectionManager.addItemAt(sequence, oEventHandler.getEvent(),
oEventHandler);
}
}
validateNotifications(aNotifications:array)
{
var errorStack =
StructNew();
result.IsValid = true;
result.Errors =
ArrayNew(1);
for(var i in aNotifications)
{
var IsValid =
listenerCollectionManager.IsKeyDefined(aNotifications[i].name);
if(NOT IsValid) {
result.IsValid
= false;
ArrayAppend(result.Errors,
aNotification[i]);
}
}
return result;
}
---------------------
Now a Config really dictates what it has availabe, and an
eventhandler can exist inside another config? so in my book it shouldn't care
whether or not a "notify" element has a listener thats valid, all it cares is to
make sure certain attributes are provided and are syntatically correct. It will
let its parent class determine if the data within itself is semantically correct
as in different contexts it could varey.
Rather then throw hard errors you could throw soft ones and
inform the user "sorry your intended listener doesn't exist, please modify
this"...
What ya think.
