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

  • Home
  • SEARCH
  • 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 430861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:55:02+00:00 2026-05-12T19:55:02+00:00

I have a class as follows :- interface IFilterCondition { List<Name> ApplyFilter(List<Name> namesToFilter); }

  • 0

I have a class as follows :-

interface IFilterCondition
{
    List<Name> ApplyFilter(List<Name> namesToFilter);
}

class FilterName : IFilterCondition
{
    public NameFilterEnum NameFilterEnum{ get; set; }

    public List<Name> ExcludeList { get; set; }

    public char StartCharacter{ get; set; }

    #region IFilterCondition Members

    public List<Name> ApplyFilter(List<Name> namesToFilter)
    {
        switch (NameFilterEnum)
        {
            case NameFilterEnum.FilterFirstName:
                // Check Exclude List
                // Check Start Character
                break;
            case NameFilterEnum.FilterLastName:
                // Check Exclude List only
                break;
            default:
                break;
        }
        return namesToFilter;
    }

    #endregion
}

enum NameFilterEnum
{
    None,
    FilterFirstName,
    FilterLastName
}

Note that only if it is flagged as a FilterFirstName then it will require the StartCharacter property.

Is the above correct or should I separate out FirstName filter and LastName filter as they require different properties? Coz I think in this instance, some business rules needs to be enforced when inputing data to this class.

Please advice,
Thanks

  • 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-12T19:55:02+00:00Added an answer on May 12, 2026 at 7:55 pm

    Enumerations are often a code smell that your design isn’t quite right. In this case you could do better by refactoring the exclusion list functionality into a base class and then adding separate derived classes for the first and last name filters. The last name filter wouldn’t do anything different from the generic filter but the first name filter would also check the start character.

    interface IFilterCondition
    {
        List<Name> ApplyFilter(List<Name> namesToFilter);
    }
    
    abstract class FilterName : IFilterCondition
    {
        public List<Name> ExcludeList { get; set; }
    
        public virtual List<Name> ApplyFilter(List<Name> namesToFilter)
        {
            // Check Exclude List
            return namesToFilter;
        }
    }
    
    class FilterFirstName : FilterName
    {
        public char StartCharacter{ get; set; }
    
        public override List<Name> ApplyFilter(List<Name> namesToFilter)
        {
            namesToFilter = base.ApplyFilter(namesToFilter);
    
            // Check Start Character
            return namesToFilter;
        }
    }
    
    class FilterLastName : FilterName
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface declared as follows public interface ILoadObjects<T> where T : class
I have a class defined as follows interface ITest { List<T> Find<T>(int i); }
I have ViewModel class as follows: public class ListViewModel { public ObservableCollection<InfoItem> List {
I have a service set up as follows: public interface IMyService { void AddCountry(string
I have got a template class as follows: class MyClass<T> { T field; public
I have a controller with an action method as follows: public class InventoryController :
I'm trying to use the Visitor Pattern and I have as follows: public class
I have a hibernate mapping as follows: <hibernate-mapping> <class name=kochman.elie.data.types.InvoiceTVO table=INVOICE> <id name=id column=ID>
I have an interface ITransaction as follows: public interface ITransaction { DateTime EntryTime {
I have a interface as follows public interface IX { void MethodA(); void MethodB();

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.