Skip to content

Gendarme.Rules.Smells.AvoidSpeculativeGeneralityRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

AvoidSpeculativeGeneralityRule

Assembly: Gendarme.Rules.Smells
Version: git

Description

This rule allows developers to avoid the Speculative Generality smell. Be careful if you are developing a new framework or a new library, because this rule only inspects the assembly, then if you provide an abstract base class for extend by third party people, then the rule can warn you. You can ignore the message in this special case. We detect this smell by looking for:

  • Abstract classes without responsibility
  • Unnecessary delegation.
  • Unused parameters.

Examples

Bad example:

// An abstract class with only one subclass.
public abstract class AbstractClass {
    public abstract void MakeStuff ();
}
public class OverriderClass : AbstractClass {
    public override void MakeStuff ()
    {
    }
}

If you use Telephone class only in one client, perhaps you don't need this kind of delegation.

public class Person {
    int age;
    string name;
    Telephone phone;
}
public class Telephone {
    int areaCode;
    int phone;
}

Good example:

public abstract class OtherAbstractClass{
    public abstract void MakeStuff ();
}
public class OtherOverriderClass : OtherAbstractClass {
    public override void MakeStuff ()
    {
    }
}
public class YetAnotherOverriderClass : OtherAbstractClass {
    public override void MakeStuff ()
    {
    }
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally