User Control Panel
Advertisements

HELP US, HELP YOU!

Sonora::InterfaceManager::Factory

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Modules & Add-ons
View unanswered posts
Author Message
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Wed Dec 08, 2004 5:16 pm    Post subject: Reply with quote

This is an addon on to sonora. It inherits from Sonora::InterfaceManager so all of its methods are available. It then adds a single method createInterface. This will create and add an interface. It also returns the interface object back so that you can do anything special needed with handlers etc per interface.

The reason I wanted this was so that I can load my configuration straight out of a file (XML for me!) and have it automaticaly include the needed modules and create the interfaces.

So without further ado the before and after example.

before:
Code:
use Sonora::InterfaceManager;<br />use Sonora::Interface::IRC;<br />use Sonora::Interface::MSN;<br /><br />my $sim = new Sonora::InterfaceManager;<br /><br />my $irc = new Sonora::Interface::IRC( 'Key'      => 'IRC1',<br />                                      'Hostname' => 'irc.slashnet.org',<br />                                      'Username' => 'bot name here');<br />$sim->addInterface($irc);<br /><br />my $msn = new Sonora::Interface::MSN( 'Key'      => 'MSN1', <br />                                      'Username' => 'botemail@hotmail.com',<br />                                      'Password' => 'testtestest'); <br />$sim->addInterface($msn);<br />


and now:
Code:
<br />use Sonora::InterfaceManager::Factory;<br /><br />my $sim = new Sonora::InterfaceManager::Factory;<br /><br />my $irc1  = $sim->createInterface('IRC', 'Key'      => 'IRC1',<br />                                         'Hostname' => 'irc.slashnet.org',<br />                                         'Username' => 'Darwin256');<br /><br />my $msn1  = $sim->createInterface('MSN', 'Key'      => 'MSN1', <br />                                         'Username' => 'botemail@hotmail.com',<br />                                         'Password' => 'testtestest');<br /> <br />


Now remember this isn't realy a lot of use if you are hand coding the connections anyway. When i'm hand coding them I just use the regular InterfaceManager object. Now that I would like to have a config file though, this adds just another layer of ease.

Let me know what you think.

To install: Goto where you installed sonora at. Along side the Interface folder add a "InterfaceManager" folder. Then save this file inside that directory.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
farkie
God Like
God Like


Joined: 15 Nov 2003
Posts: 673

Reputation: 3.4Reputation: 3.4Reputation: 3.4

PostPosted: Thu Dec 09, 2004 8:37 am    Post subject: Reply with quote

looks cool Wink
Back to top
darkmonkey
The Merovingian
The Merovingian


Joined: 18 Apr 2004
Posts: 2557
Location: London, England
Reputation: 39.3Reputation: 39.3Reputation: 39.3Reputation: 39.3
votes: 7

PostPosted: Thu Dec 09, 2004 5:04 pm    Post subject: Reply with quote

Good work.

It may be better to, instead of making lots of addon modules, work together to add it all into the main module, with options to use it or not. Just an idea.

_________________
~ Josh
[ Need bot hosting on a dedicated server? PM me. ]
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Thu Dec 09, 2004 5:13 pm    Post subject: Reply with quote

That certainly is a good point darkmonkey. I could actualy change the modules so that you do

Code:
<br />use Sonora::InterfaceManager;<br />use Sonora::InterfaceManager::Factory;<br />


And have the factory add the code straight into the manager. Then you could install as many *features* as you want, if they all play nice that way.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Mojave
Almost An Agent
Almost An Agent


Joined: 01 Nov 2003
Posts: 1434

Reputation: 66.4

PostPosted: Thu Dec 09, 2004 6:25 pm    Post subject: Reply with quote

It's tempting to want to lump everything together into one module, especially when the add-on is only 20 lines of code, like the Factory. But you don't want to program things that way just for the sake of making it easy. Conceptually and practically, it makes sense to keep the Manager code separate from the Factory code. The Manager manages a group of interfaces, while the Factory produces interfaces - they are separate and distinct functionality.

It's possible that future Interfaces will not be in the Sonora::Interface hierarchy, so putting this one function in the Manager is limiting. Similarly, I expect the Factory module to grow and include code that lets you build Interfaces from XML files, from text files, from database records and other structures.

One of the major tenets of Object Oriented programming is to create clearly defined classes. If I combined these two classes now, I can almost guarantee I'd be pulling the Factory out of the Manager a few months down the line.

Ultimately, I see the code changing to work like this:

Code:
use Sonora::InterfaceManager;<br />use Sonora::InterfaceFactory;<br /><br />my $sim = new Sonora::InterfaceManager;<br /><br />my $irc = Sonora::InterfaceFactory::create( 'Type' => 'IRC', 'Key' => 'IRC1',<br />                                     'Hostname' => 'irc.slashnet.org',<br />                                     'Username' => 'bot name here');<br />$sim->addInterface($irc);<br /><br />my $msn = Sonora::InterfaceFactory::createFromFile( 'MSN.xml' );<br />$sim->addInterface($msn);
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Modules & Add-ons All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group