Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:22:51+00:00 2026-06-01T15:22:51+00:00

DRY – Don’t Repeat Yourself ControlSignUp and ControSignIn are nearly identical. I’ve commented a

  • 0

DRY – Don’t Repeat Yourself

ControlSignUp and ControSignIn are nearly identical. I’ve commented a “here” on the only 4 lines which are different. How can I combine this common functionality?

Actually it seem obvious..I can just pass in a single variable through the constructor…just a sec.

Answer:

 /**
 *      ControlSign
 */

var ControlSign = function( type ) 
{
    var form_element = document.getElementById( type ); 
    var response_element = document.getElementById( type + '_response' ); 
    var text_object = new Text( form_element );
    var message_object = new Message( response_element );

    this.invoke = function( ) 
    {
        if( Global.validate_input_on === 1 )
        {
            if( !text_object.checkEmpty() ) 
            {
                message_object.display( 'empty' );
                return false;
            }
            if( type === 'signup' && !text_object.checkPattern( 'name' ) ) 
            {
                message_object.display( 'name' );
                return false;
            }
            if( !text_object.checkPattern( 'email' ) ) 
            {
                message_object.display( 'email' );
                return false;
            }
            if( !text_object.checkPattern( 'pass' ) ) 
            {
                message_object.display( 'pass' );
                return false;
           }
        }
        AjaxNew.repeatUse( ajaxSerialize( form_element ) + '&ajax_type=' + type + '_control', function( server_response_text ) { ajaxType( server_response_text, response_element, 'respond' ); } );
    }
};

ControlSign.in = function()
{
    new ControlSignIn( 'signin' ).invoke();
};
ControlSign.up = function()
{
    new ControlSignUp( 'signup' ).invoke();
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:22:53+00:00Added an answer on June 1, 2026 at 3:22 pm

    Simple solution: Make it a function ControlSign with a parameter, invoked with "in" or "up". You could call this “factory pattern”.

    Complex solution: you use a factory function to create the two constructors. OK, what I meant is the use of a closure to create constructors:

    function makeControlSign(type) {
        function constructor(...) {
            this.invoke = function(){...};
            // use the variable "type" where needed
            ...
         }
         constructor[type] = function(){...};
         return constructor;
    }
    var ControlSignUp = makeControlSign("up");
    var ControlSignIn = makeControlSign("in");
    

    I guess this should neither be called “factory pattern” nor “abstract factory pattern”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to follow one of rails basic rules DRY (don't repeat yourself) I
I'm having a problem with the DRY principle (Don't Repeat Yourself) and minimizing dependencies
I love the concept of DRY (don't repeat yourself [oops]), yet C++'s concept of
Are there static analysis tools for Asp.Net that measure the DRY-ness (Don't Repeat Yourself)
Frameworks such as Django help to satisfy the DRY principle(don't repeat yourself) for python.
Trying not to repeat myself (to be DRY) here, help me out. =) I
Do all git commands have a --dry-run option, or one which would indicate what
Is there a way to DRY this CSS up? Only difference is color? div.base-text-gold
I am using Ruby on Rails 3.0.7 and I would like to DRY (Don't
Here is a snippet of my JavaScript Code that I want to DRY up:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.