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 6715693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:38:39+00:00 2026-05-26T08:38:39+00:00

Suppose you had such code: public Base { abstract void Register(); } public Registrator1:

  • 0

Suppose you had such code:

public Base
{
   abstract void Register();
}

public Registrator1: Base
{
   override void Register()
   {
      //uses the current state of the object to populate the UI captions
   }
}

public Registrator2: Base
{
   override void Register()
   {
      //uses the current state of the object to populate the UI captions
   }
}

But When you receive a new business rule asking you to write Registrator3 which actually registers based on some parameter and you change your code base to the next:

public Base
{
   abstract void Register(externalParam);
}

public Registrator1: Base
{
   override void Register(externalParam)
   {
      //uses the current state of the object to populate theUI
   }
}

public Registrator2: Base
{
   override void Register(externalParam)
   {
      //uses the current state of the object to populate the UI
   }
}

public Registrator3: Base
{
   override void Register(externalParam)
   {
     //uses a DDD - service passed in the params to populate the UI
   }
}

But Registrator1 and Registrator2 do not need that param and the code becomes smelly. What are the ways to re-write this code?

  • 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-05-26T08:38:40+00:00Added an answer on May 26, 2026 at 8:38 am

    You could use an object as a parameter here; which is commonly used in scenarios where the number of parameters can vary depending on the call being used.

    struct RegistrationInfo
    {
        public static readonly RegistrationInfo Empty = new RegistrationInfo();
        public string Username;
        public string CustomerName;
        public string Validity; 
    }
    
    abstract class Base
    {
        public abstract void Register(RegistrationInfo info);
        // If you want to retain the paramaterless call:
        public void Register()
        {
             Register(RegistrationInfo.Empty);
        }
    }
    
    class Registrar1 : Base
    {
        public override void Register(RegistrationInfo info)
        {
            if (info.Username == null) throw new ArgumentNullException("info.Username");
        }
    }
    
    class Registrar2 : Base
    {
        public override void Register(RegistrationInfo info)
        {
            if (info.CustomerName == null) throw new ArgumentNullException("info.CustomerName");
        }
    }
    

    This has the advantage that you don’t need to change method parameters (which is breaking interface) each time a parameter is added. The usage also becomes somewhat self-documenting:

    var r = new Registrar1();
    r.Register(new RegistrationInfo(){ Username = "JimJoe" });
    r.Register(RegistrationInfo.Empty);
    

    It’s like air freshener for this type of code smell, while it’s still smelly; you can make it smell nicer.

    Finally you can make the call-site cleaner by making it a params argument (this has a small amount of overhead); in all honesty though it is more smelly because it’s a language hack. Finally you could improve it with generics:

    class RegistrationInfo
    {
    
    }
    
    class RegistrationInfo1 : RegistrationInfo
    {
        public string Arg;
    }
    
    class RegistrationInfo2 : RegistrationInfo
    {
        public int Arg;
    }
    
    interface IBase<in TRegistration>
        where TRegistration : RegistrationInfo
    {
        void Register(TRegistration registration);
    }
    
    class Base : IBase<RegistrationInfo>
    {
        public void Register(RegistrationInfo registration)
        {
    
        }
    }
    
    class Registrar1 : IBase<RegistrationInfo1>
    {
        public void Register(RegistrationInfo1 arg)
        {
        }
    }
    
    class Registrar2 : IBase<RegistrationInfo2>
    {
        public void Register(RegistrationInfo2 arg)
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you had code like this: _READERS = None _WRITERS = None def Init(num_readers,
I've found that in my code i release object which had never been allocated
Suppose I had the string 1 AND 2 AND 3 OR 4, and want
Suppose you had this: def wipeProduct(hash, nameToDelete) hash.each do |i| key = i[0] productName
Suppose I had a WCF service that I have coded up, like Clemens Vasters's
For example, suppose I had written my own class which allowed me to record
Suppose I only had the regular J2SE http libraries but wanted to write a
Suppose I'm making a JDBC call and I had fetched data from a database
Suppose I wanted to create a WCF WebHTTP service (ServiceREST) that had a reference
Suppose I have written such a class (number of functions doesn't really matter, but

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.