I recently updated my PHP library to use the dependency injection pattern. Wrather than instantiating objects in my classes, I instantiate them in a class called ObjectMaker and pass the objects in through object "getter" functions.
The only point I can see to doing this is for isolating faults caused by instantiation.
But since I am just one guy, and I'm not doing any unit testing I don't see any point to updating my JavaScript to use the dependency injection pattern.
These dependencies just don't cause me any problems.
Can I not used it and still call my JavaScript professional?
I'm not going to see any performance gains by using it, just more abstract code ( objects creating objects ) - I favor a simple object model with not a lot of "pattern" use. This is style preference correct?
Question?
Can I not use the dependency injection pattern and still call my JavaScript professional level?
/**
*Control
*/
var Control = ( function ()
{
var Control = function ( type )
{
this.TIME = 4000;
this.form_element = document.getElementById( type ),
this.response_element = document.getElementById( type + '_response' );
this.text_object = new Text( this.form_element ),
this.message_object = new Message( this.response_element ),
this.effects_object= new Effects( this.response_element );
};
Control.prototype.invoke = function( )
{
if( Global.validate_input_on === 1 )
{
if( !this.text_object.checkEmpty() )
{
this.message_object.display( 'empty' );
this.effects_object.fade( 'down', this.TIME );
return false;
}
if( type === 'signup' && !this.text_object.checkPattern( 'name' ) )
{
this.message_object.display( 'name' );
this.effects_object.fade( 'down', this.TIME );
return false;
}
if( !this.text_object.checkPattern( 'email' ) )
{
this.message_object.display( 'email' );
this.effects_object.fade( 'down', this.TIME );
return false;
}
if( !this.text_object.checkPattern( 'pass' ) )
{
this.message_object.display( 'pass' );
this.effects_object.fade( 'down', this.TIME );
return false;
}
}
var response_element = this.response_element;
AjaxNew.repeatUse( ajaxSerialize( this.form_element ) + '&ajax_type=' + type + '_control', function( server_response_text ) { ajaxType( server_response_text, this.response_element, 'respond' ); } );
};
Control.in = function()
{
new Control( 'signin' ).invoke();
};
Control.up = function()
{
new Control( 'signup' ).invoke();
};
Control.out = function()
{
AjaxNew.repeatUse( '&ajax_type=ControlSignOut', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
};
Control.try = function()
{
AjaxNew.repeatUse( '&ajax_type=ControlTryIt', function( server_response_text ) { ajaxType( server_response_text, 0, 'simple' ); } );
};
return Control;
} () );