Title: RE: [CFCDev] Erm, DataLayer Factory Question.

Ok, Had a bit of a thought, and how about this concept instead.(Using Actionscript here so bare with me).
 
The concept is pretty simplistic in its design, in that the "Listener" class kind of becomes "application aware". In that, Mach-II the rule of thumb is a Listener can know about the framework and how to mine for information contained within the config.xml - so its smart enough to initialize the model.


At this point i could shift all the internal logic within a listener, to say a facade or something like that.. but for this example, i'll keep it inside the listener.. (you could always refactor this part elswhere).

Now:

A) Does this sound OOP friendly?
B) Is it flawed? Ie did I miss something important?
C) Any Ideas suggestions (without building a new framework unto itself lol!)
D) Is this an example of pattern abuse.

Thanks to those who are reading this and wanting to help! - Scott Out.


CODE:
Here is the code (I've also attached it as a .txt file aswell - in case some of your email servers block dont block and wnat to retain formatting)

##############################################################################
 
Listener.class
--------------------------
   
class Listener extends framework.Listener {
 
 function Listener():Void {
  // Get Configuration Settings (ie XML file), lets pretend it returns a struct
         configSettings = getConfigurationSettings();
 
  // Lets pretend the config says "i am using SQL"
  blogFactory = new com.blog.factorySQL(configSettings);
  forumFactory = new com.forums.factorySQL(configSettings);
 
  // I thought I would put a "messenger" factory here.
  // Reason being is typically its email, but you may want other ones..(SMS?)
  MessageFactory = new com.messengers.factoryEmail(configsettings);
 
 
  // Create "Managers/AppServices" and initialize them.
  blogAppService = new com.blog.appService(blogFactory);
  forumAppService = new com.forums.appService(forumFactory);
 
 
 }
 

 function onNewBlogEntryRequest(args..):Void {
  blogAppService.createEntry(args); 
 }
 
 function getConfigurationSettings() {
 
  // Read XML config / Memory Scope etc..
  stCOnfigDetails = ReturnedInformationFromConfigFile etc..
  return stConfigDetails;
 }
}
 
com.blog.appService.class
--------------------------
class com.blog.appService {
 
 function appService(oFactory:com.blog.abstractBlogFactoryClass):Void {
  local.factory = oFactory;
 }
 
 function createEntry (args):Void {
  // Validate the entry via Bean
  EntryBean = new com.blog.EntryBean();
  EntryBean.setTitle(arg1);
  EntryBean.setBody(arg2);
  // etc..
 
  // Now Lets save that data to the persist layer.
  local.factory.getEntryDAO().create(entryBean.getMemento());
 }
}
 
 
 
com.blog.factory.class
--------------------------
class blog.factorySQL.class extends com.blog.abstractBlogFactoryClass {
 
 
 function getEntryDAO() {
 
  if(local.enteryDAO == undefined) {
   local.entryDAO = new com.blog.entryDAOSQL(local.DSN);
  }
 
  return local.entryDAO;
 }
}
 

com.blog.abstractBlogFactory.class
--------------------------
 
class com.blog.abstractBlogFactory.class {
 
 function abstractBlogFactory(configSettings) {
  local.DSN = configSettings.DSN;
 }
 
 function getEntryDAO() {
  // I am an abstract method, i need to be overriden.
  throw "Error: I wasn't overriden, and i'm not smart enough to know what type of persist layer i'm to use.
 }
}
 
com.blog.entryDAOSQL.class
--------------------------
class com.blog.entryDAOSQL {
 
 function entryDAOSQL(DSN) {
  local.DSN = arguments.DSN;
 }
 
 function create(args) {
 
  // Step 1. Check to make sure data isn't already there and is unique
  <insert db logic here to check data>
 
 
  if(step1 = true) {
  
   // Step 2. Save the Data...
   <insert db logic INSERT data>
  } else {
   throw exception here or not..
  }
 
 }
}

 

Listener.class 
--------------------------
    
class Listener extends framework.Listener {

        function Listener():Void {
                // Get Configuration Settings (ie XML file), lets pretend it 
returns a struct
                configSettings = getConfigurationSettings();
                
                // Lets pretend the config says "i am using SQL"
                blogFactory = new com.blog.factorySQL(configSettings);
                forumFactory = new com.forums.factorySQL(configSettings);

                // I thought I would put a "messenger" factory here.
                // Reason being is typically its email, but you may want other 
ones..(SMS?)
                MessageFactory = new 
com.messengers.factoryEmail(configsettings);

                
                // Create "Managers/AppServices" and initialize them.
                blogAppService = new com.blog.appService(blogFactory);
                forumAppService = new com.forums.appService(forumFactory);

                
        }


        function onNewBlogEntryRequest(args..):Void {
                blogAppService.createEntry(args);               
        }
        
        function getConfigurationSettings() {
                
                // Read XML config / Memory Scope etc..
                stCOnfigDetails = ReturnedInformationFromConfigFile etc..
                return stConfigDetails;
        }
}

com.blog.appService.class
--------------------------
class com.blog.appService {

        function appService(oFactory:com.blog.abstractBlogFactoryClass):Void {
                local.factory = oFactory;
        }

        function createEntry (args):Void {
                // Validate the entry via Bean
                EntryBean = new com.blog.EntryBean();
                EntryBean.setTitle(arg1);
                EntryBean.setBody(arg2);
                // etc..

                // Now Lets save that data to the persist layer.
                local.factory.getEntryDAO().create(entryBean.getMemento());
        }
}



com.blog.factory.class
--------------------------
class blog.factorySQL.class extends com.blog.abstractBlogFactoryClass {
        

        function getEntryDAO() {

                if(local.enteryDAO == undefined) {
                        local.entryDAO = new com.blog.entryDAOSQL(local.DSN);
                }
                
                return local.entryDAO;
        }
}


com.blog.abstractBlogFactory.class
--------------------------

class com.blog.abstractBlogFactory.class {
        
        function abstractBlogFactory(configSettings) {
                local.DSN = configSettings.DSN;
        }
        
        function getEntryDAO() {
                // I am an abstract method, i need to be overriden.
                throw "Error: I wasn't overriden, and i'm not smart enough to 
know what type of persist layer i'm to use.
        }
}

com.blog.entryDAOSQL.class
--------------------------
class com.blog.entryDAOSQL {
        
        function entryDAOSQL(DSN) {
                local.DSN = arguments.DSN;
        }

        function create(args) {
                
                // Step 1. Check to make sure data isn't already there and is 
unique
                <insert db logic here to check data>
                
                
                if(step1 = true) {
                        
                        // Step 2. Save the Data...
                        <insert db logic INSERT data>
                } else {
                        throw exception here or not..
                }

        }
}

Reply via email to